this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

removed oid switching, unsafe the way I was doing it and other tested ways were slow

+1 -20
+1 -20
lib/CHI/Driver/MongoDB.pm
··· 15 15 has 'collection' => ( is => 'ro', isa => 'MongoDB::Collection' ); 16 16 has 'db_name' => ( is => 'ro', isa => 'Str', default => 'chi' ); 17 17 has 'safe' => ( is => 'rw', isa => 'Bool', default => 0 ); 18 - has 'use_oid' => ( is => 'rw', isa => 'Bool', default => 0 ); 19 18 20 19 __PACKAGE__->meta->make_immutable(); 21 20 ··· 36 35 37 36 sub fetch { 38 37 my ( $self, $key ) = @_; 39 - $key = 40 - ( $self->{use_oid} ) 41 - ? MongoDB::OID->new( value => unpack( "H*", $key ) ) 42 - : $key; 43 38 44 39 my $results = $self->collection->find_one( { _id => $key }, { data => 1 } ); 45 40 return ($results) ? $results->{data} : undef; ··· 47 42 48 43 sub store { 49 44 my ( $self, $key, $data ) = @_; 50 - $key = 51 - ( $self->{use_oid} ) 52 - ? MongoDB::OID->new( value => unpack( "H*", $key ) ) 53 - : $key; 54 45 55 46 $self->collection->save( { _id => $key, data => $data }, 56 47 { safe => $self->{safe} } ); ··· 59 50 60 51 sub remove { 61 52 my ( $self, $key ) = @_; 62 - $key = 63 - ( $self->{use_oid} ) 64 - ? MongoDB::OID->new( value => unpack( "H*", $key ) ) 65 - : $key; 66 53 67 54 $self->collection->remove( { _id => $key }, { safe => $self->{safe} } ); 68 55 return; ··· 74 61 } 75 62 76 63 sub get_keys { 77 - return ( !shift->{use_oid} ) 78 - ? map { $_->{_id} } shift->collection->find( {}, { _id => 1 } )->all 79 - : croak 'Cannot get keys when converting keys to OID'; 64 + map { $_->{_id} } shift->collection->find( {}, { _id => 1 } )->all; 80 65 } 81 66 82 67 sub get_namespaces { ··· 140 125 =item safe 141 126 142 127 Optional flag to confirm insertion/removal. This will slow down writes significantly. 143 - 144 - =item use_oid 145 - 146 - Optional flag to convert key to OID. This speeds up gets, slows retrieval, and removes the ability to get_keys. 147 128 148 129 =back 149 130