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

jesse at bestpractical.com jesse at bestpractical.com
Sun Jan 4 17:28:39 EST 2009


Author: jesse
Date: Sun Jan  4 17:28:39 2009
New Revision: 17549

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

Log:
* minor renaming toward being able to store per-record transactions


Modified: sd/trunk/lib/App/SD/ForeignReplica.pm
==============================================================================
--- sd/trunk/lib/App/SD/ForeignReplica.pm	(original)
+++ sd/trunk/lib/App/SD/ForeignReplica.pm	Sun Jan  4 17:28:39 2009
@@ -4,26 +4,26 @@
 
 extends 'Prophet::ForeignReplica';
 
-=head2 prophet_has_seen_transaction $transaction_id
+=head2 prophet_has_seen_foreign_transaction $transaction_id $foreign_record_id
 
 Given an transaction id, will return true if this transaction originated in Prophet 
 and was pushed to RT or originated in RT and has already been pulled to the prophet replica.
 
-=cut
 
-# This is a mapping of all the transactions we have pushed to the
-# remote replica we'll only ever care about remote sequence #s greater
-# than the last transaction # we've pulled from the remote replica
-# once we've done a pull from the remote replica, we can safely expire
-# all records of this type for the remote replica (they'll be
-# obsolete)
+This is a mapping of all the transactions we have pushed to the
+remote replica we'll only ever care about remote sequence #s greater
+than the last transaction # we've pulled from the remote replica
+once we've done a pull from the remote replica, we can safely expire
+all records of this type for the remote replica (they'll be
+obsolete)
 
-# we use this cache to avoid integrating changesets we've pushed to the remote replica when doing a subsequent pull
+We use this cache to avoid integrating changesets we've pushed to the remote replica when doing a subsequent pull
 
+=cut
 
-sub prophet_has_seen_transaction {
+sub prophet_has_seen_foreign_transaction {
     my $self = shift;
-    my ($id) = validate_pos( @_, 1 );
+    my ($id, $record) = validate_pos( @_, 1, 1);
     return $self->_changeset_id_storage->( $self->uuid . '-txn-' . $id );
 }
 
@@ -34,7 +34,9 @@
 the push encoder for the foreign replica's type and call integrate_change
 on it.
 
-To avoid publishing prophet-private data, It skips any change whos record_type starts with '__'.
+To avoid publishing prophet-private data, It skips any change with a record type
+that record_type starts with '__'.
+
 This is probably a bug.
 
 =cut

Modified: sd/trunk/lib/App/SD/Replica/hm/PullEncoder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/hm/PullEncoder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/hm/PullEncoder.pm	Sun Jan  4 17:28:39 2009
@@ -94,6 +94,7 @@
 # hiveminder transaction ~= prophet changeset
 # hiveminder taskhistory ~= prophet change
 # hiveminder taskemail ~= prophet change
+#
 sub find_matching_transactions {
     my $self = shift;
     my %args = validate( @_, { task => 1, starting_transaction => 1 } );
@@ -103,7 +104,7 @@
     for my $txn (@$txns) {
         next if $txn->{'id'} < $args{'starting_transaction'};    # Skip things we've pushed
 
-        next if $self->sync_source->prophet_has_seen_transaction( $txn->{'id'} );
+        next if $self->sync_source->prophet_has_seen_foreign_transaction( $txn->{'id'}, $args{task} );
 
         $txn->{history_entries} = $self->sync_source->hm->search( 'TaskHistory', transaction_id => $txn->{'id'} );
         $txn->{email_entries}   = $self->sync_source->hm->search( 'TaskEmail',   transaction_id => $txn->{'id'} );
@@ -172,32 +173,6 @@
     return $res;
 }
 
-sub warp_list_to_old_value {
-    my $self       = shift;
-    my $task_value = shift || '';
-    my $add        = shift;
-    my $del        = shift;
-
-    my @new = split( /\s*,\s*/, $task_value );
-    my @old = grep { $_ ne $add } @new, $del;
-    return join( ", ", @old );
-}
-
-our $MONNUM = {
-    Jan => 1,
-    Feb => 2,
-    Mar => 3,
-    Apr => 4,
-    May => 5,
-    Jun => 6,
-    Jul => 7,
-    Aug => 8,
-    Sep => 9,
-    Oct => 10,
-    Nov => 11,
-    Dec => 12
-};
-
 sub translate_props {
     my $self      = shift;
     my $changeset = shift;

Modified: sd/trunk/lib/App/SD/Replica/rt.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/rt.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/rt.pm	Sun Jan  4 17:28:39 2009
@@ -51,23 +51,29 @@
     my %args = validate( @_,
         { ticket => 1, changeset => { isa => 'Prophet::ChangeSet' } } );
 
-    for my $txn (
-        reverse RT::Client::REST::Ticket->new(
+    # walk through every transaction on the ticket, starting with the latest
+    for my $txn ( reverse RT::Client::REST::Ticket->new(
             rt => $self->rt,
-            id => $args{'ticket'}
-        )->transactions->get_iterator->()
-        )
-    {
-        last
-            if $txn->id <= $self->last_changeset_from_source(
+            id => $args{'ticket'})->transactions->get_iterator->()) {
+
+        # if the transaction id is older than the id of the last changeset
+        # we got from the original source of this changeset, we're done
+        last if $txn->id <= $self->last_changeset_from_source(
                     $args{changeset}->original_source_uuid
             );
+
+        # if the transaction from RT is more recent than the most recent
+        # transaction we got from the original source of the changeset
+        # then we should record that we sent that transaction upstream
+        # XXX TODO - THIS IS WRONG - we should only be recording transactions we pushed
         $self->record_pushed_transaction(
             transaction => $txn->id,
             changeset   => $args{'changeset'}
         );
     }
 }
+
+
 =head2 uuid
 
 Return the replica's UUID

Modified: sd/trunk/lib/App/SD/Replica/rt/PullEncoder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/rt/PullEncoder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/rt/PullEncoder.pm	Sun Jan  4 17:28:39 2009
@@ -118,14 +118,12 @@
 
 =cut
 
-
 sub find_matching_tickets {
     my $self = shift;
     my ($query) = validate_pos(@_, 1);
     return $self->sync_source->rt->search( type => 'ticket', query => $query );
 }
 
-
 =head2 find_matching_transactions { ticket => $id, starting_transaction => $num }
 
 Returns a reference to an array of all transactions (as hashes) on ticket $id after transaction $num.
@@ -141,7 +139,7 @@
 
     for my $txn ( sort $rt_handle->get_transaction_ids( parent_id => $args{'ticket'} ) ) {
         next if $txn < $args{'starting_transaction'}; # Skip things we've pushed
-        next if $self->sync_source->prophet_has_seen_transaction($txn);
+        next if $self->sync_source->prophet_has_seen_foreign_transaction($txn, $args{'ticket'});
         my $txn_hash = $rt_handle->get_transaction(
             parent_id => $args{'ticket'},
             id        => $txn,
@@ -202,7 +200,6 @@
     return $changeset;
 }
 
-
 sub _recode_attachment_create {
     my $self   = shift;
     my %args   = validate( @_, { ticket => 1, txn => 1, changeset => 1, attachment => 1 } );

Modified: sd/trunk/lib/App/SD/Replica/rt/PushEncoder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/rt/PushEncoder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/rt/PushEncoder.pm	Sun Jan  4 17:28:39 2009
@@ -18,8 +18,7 @@
     local $@;
     eval {
         if (    $change->record_type eq 'ticket'
-            and $change->change_type eq 'add_file' 
-    )
+            and $change->change_type eq 'add_file' )
         {
             $id = $self->integrate_ticket_create( $change, $changeset );
             $self->sync_source->record_remote_id_for_pushed_record(
@@ -27,19 +26,25 @@
                 remote_id => $id
             );
 
-        } elsif ( $change->record_type eq 'attachment'
-            and $change->change_type eq 'add_file' 
-        
-        ) {
+        }
+        elsif (
+                $change->record_type eq 'attachment'
+            and $change->change_type eq 'add_file'
+
+          )
+        {
             $id = $self->integrate_attachment( $change, $changeset );
-        } elsif ( $change->record_type eq 'comment' 
-            and $change->change_type eq 'add_file' 
-        ) {
+        }
+        elsif ( $change->record_type eq 'comment'
+            and $change->change_type eq 'add_file' )
+        {
             $id = $self->integrate_comment( $change, $changeset );
-        } elsif ( $change->record_type eq 'ticket' ) {
+        }
+        elsif ( $change->record_type eq 'ticket' ) {
             $id = $self->integrate_ticket_update( $change, $changeset );
 
-        } else {
+        }
+        else {
             return undef;
         }
 
@@ -62,8 +67,9 @@
     );
 
     # Figure out the remote site's ticket ID for this change's record
-    my $remote_ticket_id = $self->sync_source->remote_id_for_uuid( $change->record_uuid );
-    my $ticket           = RT::Client::REST::Ticket->new(
+    my $remote_ticket_id =
+      $self->sync_source->remote_id_for_uuid( $change->record_uuid );
+    my $ticket = RT::Client::REST::Ticket->new(
         rt => $self->sync_source->rt,
         id => $remote_ticket_id,
         %{ $self->_recode_props_for_integrate($change) }



More information about the Bps-public-commit mailing list