added more link mongodb output
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 31 Jan 2010 15:22:34 +0000 (15:22 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 31 Jan 2010 15:22:34 +0000 (15:22 +0000)
lib/PXElator/httpd.pm
lib/PXElator/store.pm

index 99ae21a..8786b9f 100644 (file)
@@ -293,7 +293,9 @@ warn "XXX pids = ", dump( $daemons::pids );
                my ( $s1,$s2 ) = ( ' class=z', '' );
                my @cols;
 
-               store::query( sub {
+               my $from_t = $param->{from_t};
+
+               store::query( $from_t, sub {
                        my $o = shift;
                        my $p = delete( $o->{package} );
                        delete( $o->{_id} );
@@ -316,8 +318,11 @@ warn "XXX pids = ", dump( $daemons::pids );
                                , qq|</tr>\n|
                        ;
                        ( $s1, $s2 ) = ( $s2, $s1 );
+                       $from_t = $p->{time};
                });
-               print $client qq|</table>|;
+               print $client qq|</table>|,
+                       qq|<a href="/store/latest?from_t=$from_t">more</a>|
+               ;
 
        } elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) {
                my $ip = $1;
index 4922549..ecc675a 100644 (file)
@@ -5,13 +5,14 @@ use strict;
 
 use POSIX;
 use Time::HiRes qw/time/;
+use Data::Dump qw(dump);
 
 #use CouchDB;
 
 use MongoDB;
 
 my $conn = MongoDB::Connection->new;
-my $db = $conn->get_database( 'pxelator' );
+our $db = $conn->get_database( 'pxelator' );
 our $audit = $db->get_collection( 'audit' );
 
 
@@ -61,8 +62,12 @@ sub audit {
 
 
 sub query {
-       my $callback = shift;
-       my $cursor = $audit->query->sort({ '$natural' => -1 })->limit( 100 );
+       my ( $from_t, $callback ) = @_;
+       my $q;
+       $q = { 'package.time' => { '$lt' => $from_t * 1 } } if $from_t;
+       warn "# query ", dump($q);
+       $audit->ensure_index({ 'package.name' => 1 });
+       my $cursor = $audit->query($q)->sort({ 'package.time' => -1 })->limit( 100 );
        while( my $o = $cursor->next ) {
                $callback->( $o );
        }