[Bps-public-commit] SD branch, master, updated. 0.73-19-g2747ad9

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Oct 20 01:33:56 EDT 2009


The branch, master has been updated
       via  2747ad9f6e2a1464e4f9c0e829d93ffcdd847f38 (commit)
      from  dc2c41ce0117d5c7e1d249d0a3eaa963d41f8815 (commit)

Summary of changes:
 lib/App/SD/Replica/gcode.pm             |   11 ++++-
 lib/App/SD/Replica/gcode/PullEncoder.pm |   69 +++++++++++++++++++++++++++----
 2 files changed, 69 insertions(+), 11 deletions(-)

- Log -----------------------------------------------------------------
commit 2747ad9f6e2a1464e4f9c0e829d93ffcdd847f38
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Oct 20 13:26:17 2009 +0800

    add query string support for gcode, also hack for the performance

diff --git a/lib/App/SD/Replica/gcode.pm b/lib/App/SD/Replica/gcode.pm
index 63d286a..a9c24c5 100644
--- a/lib/App/SD/Replica/gcode.pm
+++ b/lib/App/SD/Replica/gcode.pm
@@ -37,10 +37,17 @@ sub BUILD {
     my $self = shift;
     # Require rather than use to defer load
     require Net::Google::Code;
+    require Net::Google::Code::Issue;
 
-    my ( $userinfo, $project ) = $self->{url} =~ m/^gcode:(.*@)?(.*?)$/
-        or die "Can't parse Google::Code server spec. Expected gcode:user:password\@k9mail";
+    $Net::Google::Code::Issue::USE_HYBRID = 1
+      if $Net::Google::Code::VERSION ge '0.15';
+
+    my ( $userinfo, $project, $query ) =
+      $self->{url} =~ m!^gcode:(.*@)?(.*?)(?:/(.*))?$!
+      or die
+"Can't parse Google::Code server spec. Expected gcode:k9mail or gcode:user:password\@k9mail or gcode:user:password\@k9mail/q=string&can=all";
     $self->project($project);
+    $self->query($query) if defined $query;
     my ( $email, $password );
     # ask password only if there is userinfo but not password
     if ( $userinfo ) {
diff --git a/lib/App/SD/Replica/gcode/PullEncoder.pm b/lib/App/SD/Replica/gcode/PullEncoder.pm
index 3713dcc..06ad8ce 100644
--- a/lib/App/SD/Replica/gcode/PullEncoder.pm
+++ b/lib/App/SD/Replica/gcode/PullEncoder.pm
@@ -68,20 +68,71 @@ Returns a array of all tickets found matching your QUERY hash.
 
 sub find_matching_tickets {
     my $self                   = shift;
-    my %query                  = (@_);
+    my %args  = (@_);
+    my $query = $args{query};
+    my %query;
+    if ($query) {
+        if ( $query =~ /=/ ) {
+            %query = map { /(.+)=(.*)/; $1 => $2 }
+              split /&/, $query;
+        }
+        else {
+            $query{q} = $query;
+        }
+    }
+
     my $last_changeset_seen_dt = $self->_only_pull_tickets_modified_after()
       || DateTime->from_epoch( epoch => 0 );
     $self->sync_source->log("Searching for tickets. This can take a very long time on initial sync or if you haven't synced in a long time.");
-    require Net::Google::Code::Issue::Search;
-    my $search = Net::Google::Code::Issue::Search->new(
-        project => $self->sync_source->project,
-    );
-
-    if ( $search->updated_after( $last_changeset_seen_dt ) ) {
-        return $search->results;
+    require Net::Google::Code;
+
+    if ( $Net::Google::Code::VERSION lt '0.15' ) {
+        die
+"query support is only for Net::Google::Code version not less than 0.15"
+          if $args{query};
+        require Net::Google::Code::Issue::Search;
+        my $search =
+          Net::Google::Code::Issue::Search->new(
+            project => $self->sync_source->project, );
+
+        if ( $search->updated_after($last_changeset_seen_dt) ) {
+            return $search->results;
+        }
+        else {
+            return [];
+        }
     }
     else {
-        return [];
+        my $issue = Net::Google::Code::Issue->new(
+            map { $_ => $self->sync_source->gcode->$_ }
+              grep { $self->sync_source->gcode->$_ }
+              qw/project email password/ );
+
+        if ( $last_changeset_seen_dt->epoch == 0 && keys %query == 0 ) {
+
+            # so it's clone, we can use old updated_after method here
+            # load issue with the scrapping way, which is more effective
+            local $Net::Google::Code::Issue::USE_HYBRID = 0;
+            require Net::Google::Code::Issue::Search;
+            my $search =
+              Net::Google::Code::Issue::Search->new(
+                project => $self->sync_source->project, );
+            if ( $search->updated_after( $last_changeset_seen_dt, 0 ) ) {
+                return $search->results;
+            }
+        }
+
+        $query{can} ||= 'all';
+        $query{max_results} ||= 1_000_000_000;
+        delete $query{q} unless defined $query{q};
+        my $results = $issue->list( %query,
+            updated_min => $query{updated_min}
+              && $query{updated_min} gt "$last_changeset_seen_dt"
+            ? $query{updated_min}
+            : "$last_changeset_seen_dt" );
+
+        $_->load for @$results;
+        return $results;
     }
 }
 

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



More information about the Bps-public-commit mailing list