[Bps-public-commit] Prophet branch, master, updated. e7b9d4e9e7f47f7f49ebc24fff35e30c01fa811e

jesse jesse at bestpractical.com
Fri Jun 19 11:06:00 EDT 2009


The branch, master has been updated
       via  e7b9d4e9e7f47f7f49ebc24fff35e30c01fa811e (commit)
      from  90871e7db8f4ad847deee8e03d58d1edd96111b9 (commit)

Summary of changes:
 lib/Prophet/Record.pm          |    8 +++++++-
 lib/Prophet/Replica/prophet.pm |    7 +++++--
 lib/Prophet/Replica/sqlite.pm  |   18 +++++++++++++-----
 3 files changed, 25 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit e7b9d4e9e7f47f7f49ebc24fff35e30c01fa811e
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Fri Jun 19 07:10:40 2009 -0500

    Add an API for getting the last n changesets on a record

diff --git a/lib/Prophet/Record.pm b/lib/Prophet/Record.pm
index 9ef1d6e..502e693 100644
--- a/lib/Prophet/Record.pm
+++ b/lib/Prophet/Record.pm
@@ -392,20 +392,26 @@ sub delete {
 
 }
 
-=head2 changesets
+=head2 changesets { limit => $int } 
 
 Returns an ordered list of changeset objects for all changesets containing
 changes to the record specified by this record object.
 
 Note that changesets may include changes to other records.
 
+If a limit is specified, this routine will only return that many
+changesets, starting from the changeset containing the record's
+creation.
+
 =cut
 
 sub changesets {
     my $self = shift;
+    my %args = validate(@_, { limit => 0});
     return $self->handle->changesets_for_record(
         uuid => $self->uuid,
         type => $self->type,
+        $args{limit} ? (limit => $args{limit}) : ()
     );
 }
 
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index dc7041c..a017ddc 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -588,18 +588,20 @@ sub _record_type_dir {
 # }
 
 
-=head2 changesets_for_record { uuid => $uuid, type => $type }
+=head2 changesets_for_record { uuid => $uuid, type => $type, limit => $int }
 
 Returns an ordered set of changeset objects for all changesets containing
 changes to this object. 
 
 Note that changesets may include changes to other records
 
+If "limit" is specified, only returns that many changesets (starting from record creation).
+
 =cut
 
 sub changesets_for_record {
     my $self = shift;
-    my %args = validate( @_, { uuid => 1, type => 1 } );
+    my %args = validate( @_, { uuid => 1, type => 1, limit => 0 } );
 
     my @record_index = $self->_read_record_index(
         type => $args{'type'},
@@ -616,6 +618,7 @@ sub changesets_for_record {
             sequence_no => $sequence,
             index_file  => $changeset_index
             );
+        last if (defined $args{limit} && --$args{limit});
     }
 
     return @changesets;
diff --git a/lib/Prophet/Replica/sqlite.pm b/lib/Prophet/Replica/sqlite.pm
index c26c2c4..bb00d1c 100644
--- a/lib/Prophet/Replica/sqlite.pm
+++ b/lib/Prophet/Replica/sqlite.pm
@@ -479,24 +479,32 @@ return \$index;
 
 }
 
-=head2 changesets_for_record { uuid => $uuid, type => $type }
+=head2 changesets_for_record { uuid => $uuid, type => $type, limit => $int }
 
 Returns an ordered set of changeset objects for all changesets containing
 changes to this object. 
 
+If "limit" is specified, only returns that many changesets (starting from record creation).
+
 Note that changesets may include changes to other records
 
 =cut
 
 sub changesets_for_record {
     my $self = shift;
-    my %args = validate( @_, { uuid => 1, type => 1 } );
+    my %args = validate( @_, { uuid => 1, type => 1, limit => 0 } );
 
-    my $sth = $self->dbh->prepare( "SELECT DISTINCT changesets.* "
+    my $statement = "SELECT DISTINCT changesets.* "
             . "FROM changes, changesets "
             . "WHERE  changesets.sequence_no = changes.changeset "
-            . "AND changes.record = ?"
-        );
+            . "AND changes.record = ?";
+
+    if (defined $args{limit}) {
+        $statement .= " ORDER BY changesets.sequence_no LIMIT ".$args{limit};
+
+    }
+
+    my $sth = $self->dbh->prepare( $statement    );
 
     require Prophet::ChangeSet;
     $sth->execute( $args{uuid} );

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list