]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NNTP.pm
msgmap: replace id_batch with ids_after
[public-inbox.git] / lib / PublicInbox / NNTP.pm
index 48ab7fc2547666bd1d6858d9902e8396438df7b2..b91cda1d175a3bfc2790d1aabdbcb66f5afa3bef 100644 (file)
@@ -34,7 +34,6 @@ my $LIST_HEADERS = join("\r\n", @OVERVIEW,
                        qw(:bytes :lines Xref To Cc)) . "\r\n";
 
 # disable commands with easy DoS potential:
-# LISTGROUP could get pretty bad, too...
 my %DISABLED; # = map { $_ => 1 } qw(xover list_overview_fmt newnews xhdr);
 
 my $EXPMAP; # fd -> [ idle_time, $self ]
@@ -225,15 +224,12 @@ sub cmd_listgroup ($;$) {
        }
 
        $self->{ng} or return '412 no newsgroup selected';
+       my $n = 0;
        long_response($self, 0, long_response_limit, sub {
                my ($i) = @_;
-               my $nr = $self->{ng}->mm->id_batch($$i, sub {
-                       my ($ary) = @_;
-                       more($self, join("\r\n", @$ary));
-               });
-
-               # -1 to adjust for implicit increment in long_response
-               $$i = $nr ? $$i + $nr - 1 : long_response_limit;
+               my $ary = $self->{ng}->mm->ids_after(\$n);
+               scalar @$ary or return ($$i = long_response_limit);
+               more($self, join("\r\n", @$ary));
        });
 }
 
@@ -331,20 +327,20 @@ sub cmd_newnews ($$$$;$$) {
        };
        return '.' unless @srch;
 
-       my $opts = { limit => 1000, offset => 0 };
+       my $prev = 0;
        long_response($self, 0, long_response_limit, sub {
                my ($i) = @_;
                my $srch = $srch[0];
-               my $msgs = $srch->query_ts($ts, $opts);
-               if (my $nr = scalar @$msgs) {
+               my $msgs = $srch->query_ts($ts, $prev);
+               if (scalar @$msgs) {
                        more($self, '<' .
                                join(">\r\n<", map { $_->mid } @$msgs ).
                                '>');
-                       $opts->{offset} += $nr;
+                       $prev = $msgs->[-1]->{num};
                } else {
                        shift @srch;
                        if (@srch) { # continue onto next newsgroup
-                               $opts->{offset} = 0;
+                               $prev = 0;
                        } else { # break out of the long response.
                                $$i = long_response_limit;
                        }
@@ -582,7 +578,7 @@ sub long_response ($$$$) {
        $self->{long_res} = sub {
                # limit our own running time for fairness with other
                # clients and to avoid buffering too much:
-               my $lim = 100;
+               my $lim = $end == long_response_limit ? 1 : 100;
 
                my $err;
                do {
@@ -710,20 +706,19 @@ sub hdr_searchmsg ($$$$) {
                return $r unless ref $r;
                my ($beg, $end) = @$r;
                more($self, $xhdr ? r221 : r225);
-               my $off = 0;
-               long_response($self, $beg, $end, sub {
+               my $cur = $beg;
+               long_response($self, 0, long_response_limit, sub {
                        my ($i) = @_;
-                       my $msgs = $srch->query_xover($beg, $end, $off);
-                       my $nr = scalar @$msgs or return;
-                       $off += $nr;
+                       my $msgs = $srch->query_xover($cur, $end);
+                       my $nr = scalar @$msgs or
+                                       return ($$i = long_response_limit);
                        my $tmp = '';
                        foreach my $s (@$msgs) {
                                $tmp .= $s->num . ' ' . $s->$field . "\r\n";
                        }
                        utf8::encode($tmp);
                        do_more($self, $tmp);
-                       # -1 to adjust for implicit increment in long_response
-                       $$i = $nr ? $$i + $nr - 1 : long_response_limit;
+                       $cur = $msgs->[-1]->{num} + 1;
                });
        }
 }
@@ -848,20 +843,18 @@ sub cmd_xover ($;$) {
        my ($beg, $end) = @$r;
        more($self, "224 Overview information follows for $beg to $end");
        my $srch = $self->{ng}->search;
-       my $off = 0;
-       long_response($self, $beg, $end, sub {
+       my $cur = $beg;
+       long_response($self, 0, long_response_limit, sub {
                my ($i) = @_;
-               my $msgs = $srch->query_xover($beg, $end, $off);
-               my $nr = scalar @$msgs or return;
-               $off += $nr;
+               my $msgs = $srch->query_xover($cur, $end);
+               my $nr = scalar @$msgs or return ($$i = long_response_limit);
 
                # OVERVIEW.FMT
                more($self, join("\r\n", map {
                        over_line($_->{num}, $_);
                        } @$msgs));
-
-               # -1 to adjust for implicit increment in long_response
-               $$i = $nr ? $$i + $nr - 1 : long_response_limit;
+               $cur = $msgs->[-1]->{num} + 1;
+               1;
        });
 }