[Bps-public-commit] r17155 - in sd/trunk/lib/App/SD/Replica: hm

ruz at bestpractical.com ruz at bestpractical.com
Tue Dec 9 11:08:43 EST 2008


Author: ruz
Date: Tue Dec  9 11:08:42 2008
New Revision: 17155

Modified:
   sd/trunk/lib/App/SD/Replica/hm.pm
   sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm

Log:
* use integrate_changes instead of integrate_change
* integrate 'create ticket' changes in a changeset
  earlier than other changes

Modified: sd/trunk/lib/App/SD/Replica/hm.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/hm.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/hm.pm	Tue Dec  9 11:08:42 2008
@@ -161,20 +161,16 @@
 }
 memoize '_user_info';
 
-sub _integrate_change {
-    my $self = shift;
-    my ( $change, $changeset ) = validate_pos(
-        @_,
-        { isa => 'Prophet::Change' },
-        { isa => 'Prophet::ChangeSet' }
+sub integrate_changes {
+    my ($self, $changeset) = validate_pos(
+        @_, {isa => 'Prophet::Replica'}, { isa => 'Prophet::ChangeSet' }
     );
 
-    # don't push internal records
-    return if $change->record_type =~ /^__/;
-
     require App::SD::Replica::hm::PushEncoder;
-    my $recoder = App::SD::Replica::hm::PushEncoder->new( { sync_source => $self } );
-    $recoder->integrate_change($change,$changeset);
+    my $recoder = App::SD::Replica::hm::PushEncoder->new( {
+        sync_source => $self,
+    } );
+    return $recoder->integrate_changes($changeset);
 }
 
 sub remote_uri_path_for_id {

Modified: sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm	Tue Dec  9 11:08:42 2008
@@ -7,6 +7,32 @@
     ( isa => 'App::SD::Replica::hm',
       is => 'rw');
 
+sub integrate_changes {
+    my $self = shift;
+    my ( $changeset ) = validate_pos(
+        @_, { isa => 'Prophet::ChangeSet' }
+    );
+
+    my @changes = $changeset->changes;
+    foreach my $change ( splice @changes ) {
+        # don't push internal records
+        next if $change->record_type =~ /^__/;
+
+        # integrate 'create ticket' earlier than other changes
+        if ( $change->record_type eq 'ticket'
+            and $change->change_type eq 'add_file'
+        ) {
+            $self->integrate_change( $change, $changeset );
+        } else {
+            push @changes, $change;
+        }
+    }
+
+    foreach my $change ( @changes ) {
+        $self->integrate_change( $change, $changeset );
+    }
+}
+
 
 sub integrate_change {
     my $self = shift;
@@ -103,6 +129,7 @@
     unless ( $task->{'success'} ) {
         die "Couldn't create a task: ". $self->decode_error( $task );
     }
+
     my $tid = $task->{content}->{id};
 
     if ( @requesters ) {



More information about the Bps-public-commit mailing list