[Bps-public-commit] SD branch, master, updated. 5858689cd4e10898a6725ff03955031dc6074a3e

jesse jesse at bestpractical.com
Mon May 18 16:21:20 EDT 2009


The branch, master has been updated
       via  5858689cd4e10898a6725ff03955031dc6074a3e (commit)
       via  c2dde6fd402344a8d8887c8fb8807f0edfbd11b3 (commit)
       via  a9f3e3fa9fa5712012d838e2b92b65cab8c8f253 (commit)
      from  fa5cdd14f6d003e19bff5209d5baec5d33b39462 (commit)

Summary of changes:
 lib/App/SD/ForeignReplica/PullEncoder.pm |  113 +++++++++++++++++-------------
 lib/App/SD/Replica/rt/PullEncoder.pm     |    2 +-
 2 files changed, 64 insertions(+), 51 deletions(-)

- Log -----------------------------------------------------------------
commit a9f3e3fa9fa5712012d838e2b92b65cab8c8f253
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon May 18 15:38:27 2009 -0400

    Refactor PullEncoder->run so we can override bits of it

diff --git a/lib/App/SD/ForeignReplica/PullEncoder.pm b/lib/App/SD/ForeignReplica/PullEncoder.pm
index 28420f6..7d69994 100644
--- a/lib/App/SD/ForeignReplica/PullEncoder.pm
+++ b/lib/App/SD/ForeignReplica/PullEncoder.pm
@@ -20,73 +20,87 @@ sub run {
     $self->sync_source->log("Discovering ticket history");
 
     my ( $last_txn, @changesets );
-    my $previously_modified
-        = App::SD::Util::string_to_datetime( $self->sync_source->upstream_last_modified_date );
+    my $previously_modified = App::SD::Util::string_to_datetime( $self->sync_source->upstream_last_modified_date );
 
     my $progress = Time::Progress->new();
     $progress->attr( max => $#$tickets );
 
-    local $| = 1;
-
     my $last_modified;
 
     for my $ticket (@$tickets) {
-
         $counter++;
-        my $ticket_id = $self->ticket_id($ticket);
-
+        my $changesets;
         print $progress->report( "%30b %p Est: %E\r", $counter );
-        $self->sync_source->log( "Fetching ticket $ticket_id - $counter of " . scalar @$tickets );
+        $self->sync_source->log( "Fetching $counter of " . scalar @$tickets  . " tickets");
+        ( $last_modified, $changesets ) = $self->transcode_ticket( $ticket, $last_modified );
+        unshift @changesets, @$changesets;
+    }
+
+    my $cs_counter = 0;
+    for (@changesets) {
+        $self->sync_source->log( "Applying changeset " . ++$cs_counter . " of " . scalar @changesets );
+        $args{callback}->($_);
+    }
+
+    $self->sync_source->record_upstream_last_modified_date($last_modified)
+        if ( ( $last_modified ? $last_modified->epoch : 0 ) > ( $previously_modified ? $previously_modified->epoch : 0 ) );
+
+}
+
+sub ticket_last_modified { undef}
+
+sub transcode_ticket {
+    my $self = shift;
+    my $ticket = shift;
+    my $last_modified = shift;
+    my @changesets;
+
 
         if ( my $ticket_last_modified = $self->ticket_last_modified($ticket) ) {
-            $last_modified = $ticket_last_modified
-                if ( !$last_modified || $ticket_last_modified > $last_modified );
+            $last_modified = $ticket_last_modified if ( !$last_modified || $ticket_last_modified > $last_modified );
         }
 
-        my $final_state         = $self->_translate_final_ticket_state($ticket);
-        my $ticket_initial_data = {%$final_state};
 
         my $transactions = $self->find_matching_transactions(
             ticket => $ticket,
             starting_transaction =>
                 $self->sync_source->app_handle->handle->last_changeset_from_source(
-                $self->sync_source->uuid_for_remote_id($ticket_id)
+                $self->sync_source->uuid_for_remote_id($self->ticket_id($ticket))
                 )
                 || 1
         );
 
+        my $changesets;
+       ($last_modified, $changesets) =  $self->transcode_history($ticket, $transactions, $last_modified);
+        return ($last_modified, $changesets);
+   }
+
+
+sub transcode_history {
+    my $self = shift;
+    my $ticket = shift;
+    my $transactions = shift;
+    my $last_modified = shift;
+        my $ticket_id = $self->ticket_id($ticket);
+
+    my @changesets;
         # Walk transactions newest to oldest.
         my $txn_counter = 0;
+        my $final_state         = $self->_translate_final_ticket_state($ticket);
+        my $ticket_initial_data = {%$final_state};
         for my $txn ( sort { $b->{'serial'} <=> $a->{'serial'} } @$transactions ) {
-
-            $last_modified = $txn->{timestamp}
-                if ( !$last_modified || ( $txn->{timestamp} > $last_modified ) );
-
-            $self->sync_source->log( "$ticket_id Transcoding transaction "
-                    . ++$txn_counter . " of "
-                    . scalar @$transactions );
+            warn "About to transcode ". $txn->{serial} . " -  ".$txn->{timestamp};
+            $last_modified = $txn->{timestamp} if ( !$last_modified || ( $txn->{timestamp} > $last_modified ) );
+            $self->sync_source->log( "$ticket_id Transcoding transaction " . ++$txn_counter . " of " . scalar @$transactions );
             my $changeset = $self->transcode_one_txn( $txn, $ticket_initial_data, $final_state );
             next unless $changeset && $changeset->has_changes;
 
             # the changesets are older than the ones that came before, so they goes first
             unshift @changesets, $changeset;
         }
+        return ($last_modified, \@changesets);
     }
 
-    my $cs_counter = 0;
-    for (@changesets) {
-        $self->sync_source->log(
-            "Applying changeset " . ++$cs_counter . " of " . scalar @changesets );
-        $args{callback}->($_);
-    }
-
-    $self->sync_source->record_upstream_last_modified_date($last_modified)
-        if ( ( $last_modified ? $last_modified->epoch : 0 )
-        > ( $previously_modified ? $previously_modified->epoch : 0 ) );
-
-}
-
-sub ticket_last_modified { undef}
 
 sub warp_list_to_old_value {
     my $self    = shift;

commit c2dde6fd402344a8d8887c8fb8807f0edfbd11b3
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon May 18 16:20:09 2009 -0400

    Fix a "Wrong id" bug with the rt replica type.

diff --git a/lib/App/SD/Replica/rt/PullEncoder.pm b/lib/App/SD/Replica/rt/PullEncoder.pm
index 79f0890..388c732 100644
--- a/lib/App/SD/Replica/rt/PullEncoder.pm
+++ b/lib/App/SD/Replica/rt/PullEncoder.pm
@@ -102,7 +102,7 @@ sub find_matching_transactions {
 
     my $rt_handle = $self->sync_source->rt;
     
-    my $ticket_id = $args{ticket}->{$self->sync_source->uuid . '-id'};
+    my $ticket_id = $self->ticket_id($args{ticket});
 
      my $latest = $self->sync_source->app_handle->handle->last_changeset_from_source($self->sync_source->uuid_for_remote_id( $ticket_id )) || 0;
     for my $txn ( sort $rt_handle->get_transaction_ids( parent_id => $ticket_id)) {

commit 5858689cd4e10898a6725ff03955031dc6074a3e
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon May 18 16:21:07 2009 -0400

    Perltidy

diff --git a/lib/App/SD/ForeignReplica/PullEncoder.pm b/lib/App/SD/ForeignReplica/PullEncoder.pm
index 7d69994..4265db3 100644
--- a/lib/App/SD/ForeignReplica/PullEncoder.pm
+++ b/lib/App/SD/ForeignReplica/PullEncoder.pm
@@ -8,7 +8,6 @@ sub run {
     my %args = validate( @_, { after => 1, callback => 1, } );
 
     $self->sync_source->log('Finding matching tickets');
-
     my $tickets = $self->find_matching_tickets( query => $self->sync_source->query );
 
     if ( @$tickets == 0 ) {
@@ -19,14 +18,12 @@ sub run {
     my $counter = 0;
     $self->sync_source->log("Discovering ticket history");
 
-    my ( $last_txn, @changesets );
+    my ( $last_modified, $last_txn, @changesets );
     my $previously_modified = App::SD::Util::string_to_datetime( $self->sync_source->upstream_last_modified_date );
 
     my $progress = Time::Progress->new();
     $progress->attr( max => $#$tickets );
 
-    my $last_modified;
-
     for my $ticket (@$tickets) {
         $counter++;
         my $changesets;
@@ -50,56 +47,58 @@ sub run {
 sub ticket_last_modified { undef}
 
 sub transcode_ticket {
-    my $self = shift;
-    my $ticket = shift;
+    my $self          = shift;
+    my $ticket        = shift;
     my $last_modified = shift;
     my @changesets;
 
+    if ( my $ticket_last_modified = $self->ticket_last_modified($ticket) ) {
 
-        if ( my $ticket_last_modified = $self->ticket_last_modified($ticket) ) {
-            $last_modified = $ticket_last_modified if ( !$last_modified || $ticket_last_modified > $last_modified );
-        }
-
+        warn "My last modified = " .$ticket_last_modified;
+        $last_modified = $ticket_last_modified if ( !$last_modified || $ticket_last_modified > $last_modified );
+    }
 
-        my $transactions = $self->find_matching_transactions(
-            ticket => $ticket,
-            starting_transaction =>
-                $self->sync_source->app_handle->handle->last_changeset_from_source(
-                $self->sync_source->uuid_for_remote_id($self->ticket_id($ticket))
-                )
-                || 1
-        );
+    my $transactions = $self->find_matching_transactions(
+        ticket               => $ticket,
+        starting_transaction => $self->sync_source->app_handle->handle->last_changeset_from_source(
+            $self->sync_source->uuid_for_remote_id( $self->ticket_id($ticket) )
+            ) || 1
+    );
 
-        my $changesets;
-       ($last_modified, $changesets) =  $self->transcode_history($ticket, $transactions, $last_modified);
-        return ($last_modified, $changesets);
-   }
+    my $changesets;
+    ( $last_modified, $changesets ) = $self->transcode_history( $ticket, $transactions, $last_modified );
+    return ( $last_modified, $changesets );
+}
 
 
 sub transcode_history {
-    my $self = shift;
-    my $ticket = shift;
-    my $transactions = shift;
+    my $self          = shift;
+    my $ticket        = shift;
+    my $transactions  = shift;
     my $last_modified = shift;
-        my $ticket_id = $self->ticket_id($ticket);
+    my $ticket_id     = $self->ticket_id($ticket);
 
     my @changesets;
-        # Walk transactions newest to oldest.
-        my $txn_counter = 0;
-        my $final_state         = $self->_translate_final_ticket_state($ticket);
-        my $ticket_initial_data = {%$final_state};
-        for my $txn ( sort { $b->{'serial'} <=> $a->{'serial'} } @$transactions ) {
-            warn "About to transcode ". $txn->{serial} . " -  ".$txn->{timestamp};
-            $last_modified = $txn->{timestamp} if ( !$last_modified || ( $txn->{timestamp} > $last_modified ) );
-            $self->sync_source->log( "$ticket_id Transcoding transaction " . ++$txn_counter . " of " . scalar @$transactions );
-            my $changeset = $self->transcode_one_txn( $txn, $ticket_initial_data, $final_state );
-            next unless $changeset && $changeset->has_changes;
-
-            # the changesets are older than the ones that came before, so they goes first
-            unshift @changesets, $changeset;
-        }
-        return ($last_modified, \@changesets);
+
+    # Walk transactions newest to oldest.
+    my $txn_counter         = 0;
+    my $final_state         = $self->_translate_final_ticket_state($ticket);
+    my $initial_data = {%$final_state};
+
+
+    for my $txn ( sort { $b->{'serial'} <=> $a->{'serial'} } @$transactions ) {
+        $last_modified = $txn->{timestamp} if ( !$last_modified || ( $txn->{timestamp} > $last_modified ) );
+
+        $self->sync_source->log( "$ticket_id Transcoding transaction " . ++$txn_counter . " of " . scalar @$transactions );
+
+        my $changeset = $self->transcode_one_txn( $txn, $initial_data, $final_state );
+        next unless $changeset && $changeset->has_changes;
+
+        # the changesets are older than the ones that came before, so they goes first
+        unshift @changesets, $changeset;
     }
+    return ( $last_modified, \@changesets );
+}
 
 
 sub warp_list_to_old_value {

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



More information about the Bps-public-commit mailing list