[Bps-public-commit] SD - A distributed issue tracker branch, master, updated. 0388e047d94ec33264a7373d8f5218a2541e9381
jesse
jesse at bestpractical.com
Sun Feb 8 23:51:44 EST 2009
The branch, master has been updated
via 0388e047d94ec33264a7373d8f5218a2541e9381 (commit)
via 55c331c6d2035d122f3a2bc24a22da9071c9a80c (commit)
from 9bb25827b02d806b66875922894a3f9b7641b80e (commit)
Summary of changes:
lib/App/SD/Replica/trac.pm | 6 +++---
lib/App/SD/Replica/trac/PullEncoder.pm | 32 +++++++++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 4 deletions(-)
- Log -----------------------------------------------------------------
commit 55c331c6d2035d122f3a2bc24a22da9071c9a80c
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Sun Feb 8 23:49:16 2009 -0500
Keep track of the last timestamp for more efficient sync
diff --git a/lib/App/SD/Replica/trac/PullEncoder.pm b/lib/App/SD/Replica/trac/PullEncoder.pm
index ec71455..eef6dbc 100644
--- a/lib/App/SD/Replica/trac/PullEncoder.pm
+++ b/lib/App/SD/Replica/trac/PullEncoder.pm
@@ -5,6 +5,8 @@ extends 'App::SD::ForeignReplica::PullEncoder';
use Params::Validate qw(:all);
use Memoize;
use Time::Progress;
+use DateTime;
+use DateTime::Format::ISO8601;
has sync_source => (
isa => 'App::SD::Replica::trac',
@@ -34,10 +36,14 @@ sub run {
$progress->attr( max => $#tickets );
local $| = 1;
+ my $last_modified_date;
+
for my $ticket (@tickets) {
print $progress->report( "%30b %p Est: %E\r", $counter );
$self->sync_source->log( "Fetching ticket @{[$ticket->id]} - " . $counter++ . " of " . scalar @tickets );
+ $last_modified_date = $ticket->last_modified if (!$last_modified_date || $ticket->last_modified > $last_modified_date);
+
my $ticket_data = $self->_translate_final_ticket_state($ticket);
my $ticket_initial_data = {%$ticket_data};
my $txns = $self->skip_previously_seen_transactions(
@@ -56,9 +62,18 @@ sub run {
unshift @changesets, $self->build_create_changeset( $ticket_initial_data, $ticket );
}
+ $self->_record_upstream_last_modified_date($last_modified_date);
+
$args{callback}->($_) for @changesets;
}
+sub _record_upstream_last_modified_date {
+ my $self = shift;
+ my $date = shift;
+ return $self->sync_source->store_local_metadata('last_changeset_date' => $date);
+}
+
+
sub _translate_final_ticket_state {
my $self = shift;
my $ticket_object = shift;
@@ -102,10 +117,25 @@ Returns a Trac::TicketSearch collection for all tickets found matching your QUER
sub find_matching_tickets {
my $self = shift;
my %query = (@_);
+
+
+ my $last_changeset_seen_dt;
+ if (my $last_changeset_seen = $self->sync_source->fetch_local_metadata('last_changeset_date') ) {
+ $last_changeset_seen =~ s/ /T/;
+ $last_changeset_seen_dt = DateTime::Format::ISO8601->parse_datetime( $last_changeset_seen );
+ }
+
+
my $search
= Net::Trac::TicketSearch->new( connection => $self->sync_source->trac, limit => 500 );
$search->query(%query);
- return $search->results;
+ my @results = @{$search->results};
+
+ if ($last_changeset_seen_dt) {
+ # >= is wasteful but may catch race conditions
+ @results = grep {$_->last_modified >= $last_changeset_seen_dt} @results;
+ }
+ return \@results;
}
=head2 skip_previously_seen_transactions { ticket => $id, starting_transaction => $num, transactions => \@txns }
commit 0388e047d94ec33264a7373d8f5218a2541e9381
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Sun Feb 8 23:51:33 2009 -0500
'oops'
diff --git a/lib/App/SD/Replica/trac.pm b/lib/App/SD/Replica/trac.pm
index 4fd2ce3..2542283 100644
--- a/lib/App/SD/Replica/trac.pm
+++ b/lib/App/SD/Replica/trac.pm
@@ -35,12 +35,12 @@ sub BUILD {
}
$self->remote_url( $uri->as_string );
- #( $username, $password ) = $self->prompt_for_login( $uri, $username ) unless $password;
+ ( $username, $password ) = $self->prompt_for_login( $uri, $username ) unless $password;
$self->trac(
Net::Trac::Connection->new(
url => $self->remote_url,
- user => 'jesse',#$username,
- password => 'iron' #$password
+ user => $username,
+ password => $password
)
);
$self->trac->ensure_logged_in;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list