[Bps-public-commit] r19864 - in Net-Google-Code/trunk/lib/Net/Google/Code: Issue

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Jun 3 10:07:10 EDT 2009


Author: sunnavy
Date: Wed Jun  3 10:07:09 2009
New Revision: 19864

Modified:
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm

Log:
modified column is shown --- if no comment at all. tweak for it: find the max discarded id, all the issues less than it with no modified date can be discarded

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm	Wed Jun  3 10:07:09 2009
@@ -45,8 +45,11 @@
         $args{can} = $CAN_MAP{ $args{can} };
     }
 
+    my $user_sort;
     if ( $args{updated_after} ) {
         $args{colspec} .= '+Modified' unless $args{colspec} =~ /Modified/;
+        $user_sort = $args{sort};
+        $args{sort} = '-id'; # to sort by id reversely
 
         # convert updated_after to epoch
         if ( ref $args{updated_after} ) {
@@ -92,6 +95,17 @@
             limit         => $args{limit},
             updated_after => $args{updated_after},
         );
+        if ( $user_sort && $user_sort =~ /(-)?(\w+)/ ) {
+            my $reverse = $1 ? 1 : 0;
+            my $col = $2;
+            @rows = sort {
+# if id is not the sort col, we use id as secondary sort col.
+# in this case, no matter the main order, we always sort the id ascendingly
+                $reverse
+                  ? ( $b->{$col} <=> $a->{$col} || $a->{id} <=> $b->{id} )
+                  : ( $a->{$col} <=> $b->{$col} || $a->{id} <=> $b->{id} )
+            } @rows;
+        }
 
         my @issues;
         for my $row (@rows) {

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm	Wed Jun  3 10:07:09 2009
@@ -75,11 +75,34 @@
             label_column => $label_column,
           );
         my $found_number = scalar @all_rows;
+        my $max_discarded = 0;
 
-        push @rows, grep {
-            my $epoch = UnixDate( $_->{modified}, '%o' );
-            ( $epoch && $args{updated_after} && $epoch < $args{updated_after} ) ? 0 : 1;
-          } @all_rows;
+        my $filter = sub {
+            return 1 unless $args{updated_after};
+
+            my $row = shift;
+
+            if ( $row->{modified} ) {
+                my $epoch = UnixDate( $row->{modified}, '%o' );
+                if ( $epoch < $args{updated_after} ) {
+                    $max_discarded = $row->{id} if $max_discarded < $row->{id};
+                    return;
+                }
+                else {
+                    return 1;
+                }
+            }
+            elsif ( $row->{id} < $max_discarded ) {
+   # no modified, means there is no comment, the updated date is the created
+   # since the id is less than the max discarded id, it's safe to discard it too
+                return;
+            }
+            else {
+                return 1;
+            }
+        };
+
+        push @rows, grep { $filter->($_) } @all_rows;
 
         $total = $args{limit} if $args{limit} < $total;
         while ( $found_number < $total ) {
@@ -93,12 +116,7 @@
                     );
                     $found_number += @all_rows;
 
-                    push @rows, grep {
-                        my $epoch = UnixDate( $_->{modified}, '%o' );
-                        (        $epoch
-                              && $args{updated_after}
-                              && $epoch < $args{updated_after} ) ? 0 : 1;
-                    } @all_rows;
+                    push @rows, grep { $filter->($_) } @all_rows;
                 }
                 else {
                     die "failed to follow 'Next' link";



More information about the Bps-public-commit mailing list