/[pxelator]/lib/PXElator/store.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/store.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 492 by dpavlin, Mon Jan 25 17:55:55 2010 UTC revision 522 by dpavlin, Thu Aug 26 19:29:18 2010 UTC
# Line 5  use strict; Line 5  use strict;
5    
6  use POSIX;  use POSIX;
7  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
8    use Data::Dump qw(dump);
 #use CouchDB;  
9    
10  use MongoDB;  use MongoDB;
11    
12  my $conn = MongoDB::Connection->new;  our $audit;
13  my $db = $conn->get_database( 'pxelator' );  
14  our $audit = $db->get_collection( 'audit' );  eval {
15            my $conn   = MongoDB::Connection->new;
16            my  $db    = $conn->get_database( 'pxelator' );
17            $audit = $db->get_collection( 'audit' );
18    };
19    warn "ERROR: no store for audit: $@" if $@;
20    
21    
22  sub audit {  sub audit {
# Line 56  sub audit { Line 60  sub audit {
60  #       CouchDB::_store_audit( "$time.$package.$url" => $data );  #       CouchDB::_store_audit( "$time.$package.$url" => $data );
61    
62  #       $data->{_id} = "$time.$package.$url";  #       $data->{_id} = "$time.$package.$url";
63          $audit->insert( $data );  #
64            if ( $audit ) {
65                    $audit->insert( $data );
66            } else {
67                    warn "AUDIT ",dump($data);
68            }
69  }  }
70    
71    
72  sub query {  sub query {
73          my $callback = shift;          my ( $q, $callback ) = @_;
74          my $cursor = $audit->query->sort({ '$natural' => -1 })->limit( 100 );          warn "# query ", dump($q);
75            $audit->ensure_index({ $_ => 1 }) foreach keys %$q;
76            my $cursor = $audit->query($q)->sort({ 'package.time' => -1 })->limit( 100 );
77          while( my $o = $cursor->next ) {          while( my $o = $cursor->next ) {
78                  $callback->( $o );                  $callback->( $o );
79          }          }

Legend:
Removed from v.492  
changed lines
  Added in v.522

  ViewVC Help
Powered by ViewVC 1.1.26