about summary refs log tree commit homepage
path: root/lib/PublicInbox/Msgmap.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-09-19 02:03:31 +0000
committerEric Wong <e@80x24.org>2015-09-19 04:18:38 +0000
commit7ee29d11b25b09b8919b9a125732e4c2c5784d28 (patch)
treee4b424bb8fa8e430fbf5b3842612087cc680ada7 /lib/PublicInbox/Msgmap.pm
parent0d0fde0bff97a283e3b433f2772a99fe9d6d8412 (diff)
downloadpublic-inbox-7ee29d11b25b09b8919b9a125732e4c2c5784d28.tar.gz
LISTGROUP can be expensive for giant groups, too.  Use the
long response API to improve fairness and prevent excessive
buffering.
Diffstat (limited to 'lib/PublicInbox/Msgmap.pm')
-rw-r--r--lib/PublicInbox/Msgmap.pm24
1 files changed, 8 insertions, 16 deletions
diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index c0fc636f..2f64d90c 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -155,25 +155,17 @@ sub create_tables {
                         'val VARCHAR(255) NOT NULL)');
 }
 
-sub each_id_batch {
-        my ($self, $cb) = @_;
+sub id_batch {
+        my ($self, $num, $cb) = @_;
         my $dbh = $self->{dbh};
-        my $n = 0;
-        my $total = 0;
-        my $nr;
         my $sth = $dbh->prepare('SELECT num FROM msgmap WHERE num > ? '.
                                 'ORDER BY num ASC LIMIT 1000');
-        while (1) {
-                $sth->execute($n);
-                my $ary = $sth->fetchall_arrayref;
-                @$ary = map { $_->[0] } @$ary;
-                $nr = scalar @$ary;
-                last if $nr == 0;
-                $total += $nr;
-                $n = $ary->[-1];
-                $cb->($ary);
-        }
-        $total;
+        $sth->execute($num);
+        my $ary = $sth->fetchall_arrayref;
+        @$ary = map { $_->[0] } @$ary;
+        my $nr = scalar @$ary;
+        $cb->($ary) if $nr;
+        $nr;
 }
 
 1;