this repo has no description

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

Changed files
+1 -20
lib
CHI
Driver
+1 -20
lib/CHI/Driver/MongoDB.pm
···
has 'collection' => ( is => 'ro', isa => 'MongoDB::Collection' );
has 'db_name' => ( is => 'ro', isa => 'Str', default => 'chi' );
has 'safe' => ( is => 'rw', isa => 'Bool', default => 0 );
-
has 'use_oid' => ( is => 'rw', isa => 'Bool', default => 0 );
__PACKAGE__->meta->make_immutable();
···
sub fetch {
my ( $self, $key ) = @_;
-
$key =
-
( $self->{use_oid} )
-
? MongoDB::OID->new( value => unpack( "H*", $key ) )
-
: $key;
my $results = $self->collection->find_one( { _id => $key }, { data => 1 } );
return ($results) ? $results->{data} : undef;
···
sub store {
my ( $self, $key, $data ) = @_;
-
$key =
-
( $self->{use_oid} )
-
? MongoDB::OID->new( value => unpack( "H*", $key ) )
-
: $key;
$self->collection->save( { _id => $key, data => $data },
{ safe => $self->{safe} } );
···
sub remove {
my ( $self, $key ) = @_;
-
$key =
-
( $self->{use_oid} )
-
? MongoDB::OID->new( value => unpack( "H*", $key ) )
-
: $key;
$self->collection->remove( { _id => $key }, { safe => $self->{safe} } );
return;
···
}
sub get_keys {
-
return ( !shift->{use_oid} )
-
? map { $_->{_id} } shift->collection->find( {}, { _id => 1 } )->all
-
: croak 'Cannot get keys when converting keys to OID';
+
map { $_->{_id} } shift->collection->find( {}, { _id => 1 } )->all;
}
sub get_namespaces {
···
=item safe
Optional flag to confirm insertion/removal. This will slow down writes significantly.
-
-
=item use_oid
-
-
Optional flag to convert key to OID. This speeds up gets, slows retrieval, and removes the ability to get_keys.
=back