[Bps-public-commit] r17364 - in sd/trunk/lib/App/SD: . Replica/hm Replica/rt
jesse at bestpractical.com
jesse at bestpractical.com
Thu Dec 25 20:31:03 EST 2008
Author: jesse
Date: Thu Dec 25 20:31:02 2008
New Revision: 17364
Modified:
sd/trunk/lib/App/SD/ForeignReplica.pm
sd/trunk/lib/App/SD/Replica/hm.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
Log:
* Refactoring to remove duplicated code for foreign replicas
Modified: sd/trunk/lib/App/SD/ForeignReplica.pm
==============================================================================
--- sd/trunk/lib/App/SD/ForeignReplica.pm (original)
+++ sd/trunk/lib/App/SD/ForeignReplica.pm Thu Dec 25 20:31:02 2008
@@ -47,6 +47,19 @@
);
}
+sub traverse_changesets {
+ my $self = shift;
+ my %args = validate( @_,
+ { after => 1,
+ callback => 1,
+ }
+ );
+
+ Prophet::App->require( $self->pull_encoder());
+ my $recoder = $self->pull_encoder->new( { sync_source => $self } );
+ $recoder->run(after => $args{'after'}, callback => $args{'callback'});
+
+}
sub remote_uri_path_for_id {
die "your subclass needds to implement this to be able to map a remote id to /ticket/id or soemthing";
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 Thu Dec 25 20:31:02 2008
@@ -14,6 +14,9 @@
has props => ( isa => 'HashRef[Str]', is => 'rw');
use constant scheme => 'hm';
+use constant pull_encoder => 'App::SD::Replica::hm::PullEncoder';
+use constant push_encoder => 'App::SD::Replica::hm::PushEncoder';
+
use App::SD::Replica::rt;
@@ -67,81 +70,10 @@
return $self->uuid_for_url( join( '/', $self->remote_url, $self->hm_username ) );
}
-sub traverse_changesets {
- my $self = shift;
- my %args = validate(
- @_,
- { after => 1,
- callback => 1,
- }
- );
-
- my $first_rev = ( $args{'after'} + 1 ) || 1;
-
- require App::SD::Replica::hm::PullEncoder;
- my $recoder = App::SD::Replica::hm::PullEncoder->new( { sync_source => $self } );
- for my $task ( @{ $self->find_matching_tasks } ) {
- my $changesets = $recoder->run(
- task => $task,
- transactions => $self->find_matching_transactions(
- task => $task->{id}, starting_transaction => $first_rev
- ),
- );
- $args{'callback'}->($_) for @$changesets;
- }
-}
-
-sub find_matching_tasks {
- my $self = shift;
- my %args = ();
-
- if ( my $props = $self->props ) {
- while ( my ($k, $v) = each %$props ) { $args{$k} = $v }
- }
-
- unless ( keys %args ) {
- %args = (
- owner => 'me',
- group => 0,
- requestor => 'me',
- not_complete => 1,
- );
- }
-
- my $status = $self->hm->act( 'TaskSearch', %args );
- unless ( $status->{'success'} ) {
- die "couldn't search";
- }
- return $status->{content}{tasks};
-}
-
sub record_pushed_transactions {
-
# don't need this for hm
}
-# 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 } );
-
- my $txns = $self->hm->search( 'TaskTransaction', task_id => $args{task} ) || [];
- my @matched;
- for my $txn (@$txns) {
- next if $txn->{'id'} < $args{'starting_transaction'}; # Skip things we've pushed
-
- next if $self->prophet_has_seen_transaction( $txn->{'id'} );
-
- $txn->{history_entries} = $self->hm->search( 'TaskHistory', transaction_id => $txn->{'id'} );
- $txn->{email_entries} = $self->hm->search( 'TaskEmail', transaction_id => $txn->{'id'} );
- push @matched, $txn;
- }
- return \@matched;
-
-}
-
sub user_info {
my $self = shift;
my %args = @_;
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 Thu Dec 25 20:31:02 2008
@@ -8,10 +8,28 @@
is => 'rw',
);
-our $DEBUG = $Prophet::Handle::DEBUG;
sub run {
my $self = shift;
+ my %args = validate(@_,
+ { after => 1,
+ callback => 1,
+ });
+ my $first_rev = ( $args{'after'} + 1 ) || 1;
+
+ for my $task ( @{ $self->find_matching_tasks } ) {
+ my $changesets = $self->_recode_task(
+ task => $task,
+ transactions => $self->find_matching_transactions(
+ task => $task->{id}, starting_transaction => $first_rev
+ ),
+ );
+ $args{'callback'}->($_) for @$changesets;
+ }
+}
+
+sub _recode_task {
+ my $self = shift;
my %args = validate( @_, { task => 1, transactions => 1 } );
my @changesets;
@@ -49,6 +67,52 @@
return \@changesets;
}
+sub find_matching_tasks {
+ my $self = shift;
+ my %args = ();
+
+ if ( my $props = $self->sync_source->props ) {
+ while ( my ($k, $v) = each %$props ) { $args{$k} = $v }
+ }
+
+ unless ( keys %args ) {
+ %args = (
+ owner => 'me',
+ group => 0,
+ requestor => 'me',
+ not_complete => 1,
+ );
+ }
+
+ my $status = $self->sync_source->hm->act( 'TaskSearch', %args );
+ unless ( $status->{'success'} ) {
+ die "couldn't search";
+ }
+ return $status->{content}{tasks};
+}
+
+# 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 } );
+
+ my $txns = $self->sync_source->hm->search( 'TaskTransaction', task_id => $args{task} ) || [];
+ my @matched;
+ 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'} );
+
+ $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'} );
+ push @matched, $txn;
+ }
+ return \@matched;
+
+}
+
sub add_prop_change {
my $self = shift;
my %args = validate( @_, { history_entry => 1, previous_state => 1, change => 1 } );
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 Thu Dec 25 20:31:02 2008
@@ -8,6 +8,9 @@
use Memoize;
use constant scheme => 'rt';
+use constant pull_encoder => 'App::SD::Replica::rt::PullEncoder';
+use constant push_encoder => 'App::SD::Replica::rt::PushEncoder';
+
use Prophet::ChangeSet;
@@ -94,19 +97,6 @@
}
-sub traverse_changesets {
- my $self = shift;
- my %args = validate( @_,
- { after => 1,
- callback => 1,
- }
- );
-
- require App::SD::Replica::rt::PullEncoder;
- my $recoder = App::SD::Replica::rt::PullEncoder->new( { sync_source => $self } );
- $recoder->run( query => $self->rt_query, after => $args{'after'}, callback => $args{'callback'});
-
-}
sub remote_uri_path_for_id {
my $self = shift;
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 Thu Dec 25 20:31:02 2008
@@ -16,7 +16,6 @@
@_,
{ after => 1,
callback => 1,
- query => 1
}
);
@@ -25,7 +24,7 @@
my $tickets = {};
my @transactions;
- my @tickets = $self->find_matching_tickets( $args{'query'} );
+ my @tickets = $self->find_matching_tickets( $self->sync_source->rt_query );
$self->sync_source->log("No tickets found.") if @tickets == 0;
More information about the Bps-public-commit
mailing list