about summary refs log tree commit homepage
path: root/lib/PublicInbox/Mbox.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-04-06 21:44:38 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-04-06 21:45:03 +0000
commitfad9acd35e56a289ade90a62d056b2a6663d448c (patch)
tree74d3203af13690a521d4de54ca2733223e2c389e /lib/PublicInbox/Mbox.pm
parent8f2999546c9447ce2aed48ba4d1192e0058e28a2 (diff)
downloadpublic-inbox-fad9acd35e56a289ade90a62d056b2a6663d448c.tar.gz
Favor simpler internal APIs this time around, this cuts
a fair amount of code out and takes another step towards
removing Xapian as a dependency for v2 repos.
Diffstat (limited to 'lib/PublicInbox/Mbox.pm')
-rw-r--r--lib/PublicInbox/Mbox.pm39
1 files changed, 15 insertions, 24 deletions
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index c5e1cb9c..4427ae5d 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -34,19 +34,17 @@ sub mb_stream {
 # called by PSGI server as body response
 sub getline {
         my ($more) = @_; # self
-        my ($ctx, $head, $tail, $db, $cur) = @$more;
-        if ($cur) {
+        my ($ctx, $id, $prev, $next, $cur) = @$more;
+        if ($cur) { # first
                 pop @$more;
                 return msg_str($ctx, $cur);
         }
-        for (; !defined($cur) && $head != $tail; $head++) {
-                my $smsg = PublicInbox::SearchMsg->get($head, $db, $ctx->{mid});
-                my $mref = $ctx->{-inbox}->msg_by_smsg($smsg) or next;
-                $cur = Email::Simple->new($mref);
-                $cur = msg_str($ctx, $cur);
-        }
-        $more->[1] = $head;
-        $cur;
+        $cur = $next or return;
+        my $ibx = $ctx->{-inbox};
+        $next = $ibx->search->next_by_mid($ctx->{mid}, \$id, \$prev);
+        @$more = ($ctx, $id, $prev, $next); # $next may be undef, here
+        my $mref = $ibx->msg_by_smsg($cur) or return;
+        msg_str($ctx, Email::Simple->new($mref));
 }
 
 sub close {} # noop
@@ -57,21 +55,14 @@ sub emit_raw {
         my $ibx = $ctx->{-inbox};
         my $first;
         my $more;
-        my ($head, $tail, $db);
-        my %seen;
         if (my $srch = $ibx->search) {
-                $srch->retry_reopen(sub {
-                        ($head, $tail, $db) = $srch->each_smsg_by_mid($mid);
-                        for (; !defined($first) && $head != $tail; $head++) {
-                                my @args = ($head, $db, $mid);
-                                my $smsg = PublicInbox::SearchMsg->get(@args);
-                                my $mref = $ibx->msg_by_smsg($smsg) or next;
-                                $first = Email::Simple->new($mref);
-                        }
-                        if ($head != $tail) {
-                                $more = [ $ctx, $head, $tail, $db, $first ];
-                        }
-                });
+                my ($id, $prev);
+                my $smsg = $srch->next_by_mid($mid, \$id, \$prev) or return;
+                my $mref = $ibx->msg_by_smsg($smsg) or return;
+                $first = Email::Simple->new($mref);
+                my $next = $srch->next_by_mid($mid, \$id, \$prev);
+                # $more is for ->getline
+                $more = [ $ctx, $id, $prev, $next, $first ] if $next;
         } else {
                 my $mref = $ibx->msg_by_mid($mid) or return;
                 $first = Email::Simple->new($mref);