[Bps-public-commit] r11521 - in SVN-PropDB: .

jesse at bestpractical.com jesse at bestpractical.com
Fri Apr 4 22:30:26 EDT 2008


Author: jesse
Date: Fri Apr  4 22:30:26 2008
New Revision: 11521

Modified:
   SVN-PropDB/   (props changed)
   SVN-PropDB/lib/Prophet/Sync/Source/RT.pm

Log:
 r29216 at 68-246-40-124:  jesse | 2008-04-04 16:30:16 -1000
 * refactor, refactor ok


Modified: SVN-PropDB/lib/Prophet/Sync/Source/RT.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Sync/Source/RT.pm	(original)
+++ SVN-PropDB/lib/Prophet/Sync/Source/RT.pm	Fri Apr  4 22:30:26 2008
@@ -13,7 +13,7 @@
 use Prophet::ChangeSet;
 use Prophet::Conflict;
 use Prophet::Sync::Source::RT::PullEncoder;
-
+use App::Cache;
 
 
 __PACKAGE__->mk_accessors(qw/prophet_handle ressource is_resdb rt rt_url rt_queue rt_query/);
@@ -22,6 +22,17 @@
 
 =head1 NOTES ON PUSH
 
+If the remote storage (RT) can not represent a whole changeset along with the prophet changeset uuid, then we need to 
+create a seperate locally(?) stored map of:
+    remote-subchangeset-identifier to changeset uuid.
+
+For each sync of the same remote source (RT), we need a unique prophet database domain.
+
+if clkao syncs from RT, jesse can sync with clkao but not with RT directly with the same database.
+
+
+
+
 Push to rt algorithm
 
 apply a single changeset that's part of the push:
@@ -53,12 +64,30 @@
 sub conflicts_from_changeset { return; }
 sub accepts_changesets {1}
 
+
+my $source_cache = App::Cache->new( { ttl => 60 * 60 } );    # la la la
+
 sub record_changeset_integration {
     my ( $self, $source_uuid, $source_seq ) = @_;
-    my $cache = App::Cache->new( { ttl => 60 * 60 } );    # la la la
-    return $cache->set( $self->uuid . '-' . $source_uuid, $source_seq );
+    return $source_cache->set( $self->uuid . '-' . $source_uuid, $source_seq );
+}
+
+
+=head2 last_changeset_from_source $SOURCE_UUID
+
+Returns the last changeset id seen from the source identified by $SOURCE_UUID
+
+=cut
+
+sub last_changeset_from_source {
+    my $self = shift;
+    my ($source_uuid) = validate_pos( @_, { type => SCALAR } );
+    return $source_cache->get( $self->uuid . '-' . $source_uuid ) || 0;
 }
 
+
+
+
 sub record_integration_changeset {
     warn "record_integration_changeset should be renamed to 'record_original_change";
     my ( $self, $changeset ) = @_;
@@ -90,37 +119,24 @@
 
 =cut
 
+my $txn_cache = App::Cache->new( { ttl => 60 * 60 } );                                                # la la la
+
 sub  prophet_has_seen_transaction {
     my $self = shift;
     my ($id) = validate_pos(@_, 1 );
-
-    my $cache = App::Cache->new( { ttl => 60 * 60 } );                                                # la la la
-    return $cache->get( $self->uuid. '-txn-' . $id);
+    return $txn_cache->get( $self->uuid. '-txn-' . $id);
 }
 
 sub record_pushed_transaction {
     my $self  = shift;
     my %args  = validate( @_, { transaction => 1, changeset => { isa => 'Prophet::ChangeSet' } } );
-    my $cache = App::Cache->new( { ttl => 60 * 60 } );                                                # la la la
 
-    #    warn "storing changeset metadata ".$self->uuid. " $uuid $seq / for ".join(',',@$txn_ids);
-    #    warn "===> ? ".$self->uuid.'      -txn-....'.$args{transaction};
-
-    $cache->set(
-        $self->uuid.'-txn-' . $args{transaction} => 
+    $txn_cache->set( $self->uuid.'-txn-' . $args{transaction} => 
         join( ':', $args{changeset}->original_source_uuid, $args{changeset}->original_sequence_no )
     );
 }
 
 
-sub get_remote_id_for {
-    my ( $self, $ticket_uuid ) = @_;
-    # XXX: should not access CLI handle
-    my $ticket = Prophet::Record->new( handle => Prophet::CLI->new->handle, type => 'ticket' );
-    $ticket->load( uuid => $ticket_uuid );
-    return $ticket->prop( $self->uuid . '-id' );
-}
-
 
 
 =head2 has_seen_changeset Prophet::ChangeSet
@@ -135,13 +151,7 @@
     my ($changeset) = validate_pos( @_, { isa => 'Prophet::ChangeSet' } );
         # XXXX: this is actually not right, because new_changesets_for
     # is calling has_seen_changeset on $other, rather than us
-    my $cache = App::Cache->new( { ttl => 60 * 60 } );    # la la la
-    my $txn_id = $changeset->original_sequence_no;
-
-    # XXX: extract the original txn id from $changeset
-    #    warn "===> ? ".$self->uuid,'-txn-'.$txn_id;
-    my $ret = $cache->get( $self->uuid. '-txn-' . $txn_id );
-    #    warn "==> $ret";
+    my $ret = $txn_cache->get( $self->uuid. '-txn-' . $changeset->original_sequence_no );
     return $ret;
 }
 
@@ -154,35 +164,32 @@
 
 }
 
-sub ticket_uuid {
-    my ($self, $id) = @_;
-    
-    my $cache = App::Cache->new( { ttl => 60 * 60 } );                                                # la la la
-    warn "===> ticket $id ?".$self->uuid.'-ticket-' . $id ;
-    my $uuid = $cache->get( $self->uuid.'-ticket-' . $id );
 
-    warn "=got $uuid " if $uuid;
-    return $uuid if $uuid;
-    
-    return $self->uuid_for_url( $self->rt_url . "/ticket/$id" ),
+my $ticket_cache = App::Cache->new( { ttl => 60 * 60 } );         
+
+sub get_remote_id_for {
+    my ( $self, $ticket_uuid ) = @_;
+    # XXX: should not access CLI handle
+    my $ticket = Prophet::Record->new( handle => Prophet::CLI->new->handle, type => 'ticket' );
+    $ticket->load( uuid => $ticket_uuid );
+    return $ticket->prop( $self->uuid . '-id' );
 }
 
 
 
+sub ticket_uuid {
+    my ($self, $id) = @_;
+    
+    return $ticket_cache->get( $self->uuid.'-ticket-' . $id ) || $self->uuid_for_url( $self->rt_url . "/ticket/$id" ),
+}
+
 
 sub record_pushed_ticket {
     my $self = shift;
     my %args= validate(@_, {uuid =>  1,
-                remote_id => 1
-                });
-    my $cache = App::Cache->new( { ttl => 60 * 60 } );         
-    warn "record just pushed ticket $args{remote_id} as ".        $args{uuid};
-    warn $self->uuid.'-ticket-' . $args{remote_id} ;
-
-    $cache->set(
-        $self->uuid.'-ticket-' . $args{remote_id} => 
-        $args{uuid}
-    );
+                remote_id => 1                });
+
+    $ticket_cache->set( $self->uuid.'-ticket-' . $args{remote_id} =>         $args{uuid}    );
 }
 
 sub _integrate_change {
@@ -408,23 +415,6 @@
     return \@txns;
 }
 
-=head2 last_changeset_from_source $SOURCE_UUID
-
-Returns the last changeset id seen from the source identified by $SOURCE_UUID
-
-=cut
-
-sub last_changeset_from_source {
-    my $self = shift;
-    my ($source_uuid) = validate_pos( @_, { type => SCALAR } );
-
-    use App::Cache;
-    my $cache = App::Cache->new( { ttl => 60 * 60 } );    # la la la
-
-    #$cache->delete($self->uuid.'-'.$source_uuid) || 0;
-
-    return $cache->get( $self->uuid . '-' . $source_uuid ) || 0;
-}
 
 
 1;



More information about the Bps-public-commit mailing list