X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FPXElator%2Fstore.pm;h=0f691eb106534c988c1d4d521653c5f1c14ee80c;hb=424cb3ecd7b688f50914bb10dcb45e17f487dc71;hp=a32662104eb24b57915261a6b270a06f3faee19e;hpb=fa66a7b92a0d4a34ef0d95424e7a29270a264222;p=pxelator diff --git a/lib/PXElator/store.pm b/lib/PXElator/store.pm index a326621..0f691eb 100644 --- a/lib/PXElator/store.pm +++ b/lib/PXElator/store.pm @@ -5,14 +5,18 @@ use strict; use POSIX; use Time::HiRes qw/time/; - -#use CouchDB; +use Data::Dump qw(dump); use MongoDB; -my $conn = MongoDB::Connection->new; -my $db = $conn->get_database( 'pxelator' ); -our $audit = $db->get_collection( 'audit' ); +our $audit; + +eval { + my $conn = MongoDB::Connection->new; + my $db = $conn->get_database( 'pxelator' ); + $audit = $db->get_collection( 'audit' ); +}; +warn "ERROR: no store for audit: $@" if $@; sub audit { @@ -56,17 +60,21 @@ sub audit { # CouchDB::_store_audit( "$time.$package.$url" => $data ); # $data->{_id} = "$time.$package.$url"; - $audit->insert( $data ); +# + if ( $audit ) { + $audit->insert( $data ); + } else { + warn "AUDIT ",dump($data); + } } -use Data::Dumper; sub query { - my $callback = shift; - my $cursor = $audit->query->sort({ '$natural' => -1 })->limit( 25 ); + my ( $q, $callback ) = @_; + warn "# query ", dump($q); + $audit->ensure_index({ $_ => 1 }) foreach keys %$q; + my $cursor = $audit->query($q)->sort({ 'package.time' => -1 })->limit( 100 ); while( my $o = $cursor->next ) { -# $callback->( $o ); -warn Dumper( $o ); $callback->( $o ); } }