about summary refs log tree commit homepage
path: root/lib/PublicInbox/Mbox.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-08-20 20:24:53 +0000
committerEric Wong <e@yhbt.net>2020-08-20 21:11:21 +0000
commitb63ffbe2b634daedb05b1e27fc272e2708c2bf90 (patch)
treefdcbea094010be2e76c3de1a9a6f61119f8a817b /lib/PublicInbox/Mbox.pm
parente46c349fc3b26aadb5413f8ee651f9a5016d3604 (diff)
downloadpublic-inbox-b63ffbe2b634daedb05b1e27fc272e2708c2bf90.tar.gz
Another place where we can reduce kernel page cache overhead
by hitting over.sqlite3 instead of docdata.glass.
Diffstat (limited to 'lib/PublicInbox/Mbox.pm')
-rw-r--r--lib/PublicInbox/Mbox.pm23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index a83c0356..0fa9a38d 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -10,6 +10,7 @@ use PublicInbox::MID qw/mid_escape/;
 use PublicInbox::Hval qw/to_filename/;
 use PublicInbox::Smsg;
 use PublicInbox::Eml;
+use PublicInbox::Search qw(mdocid);
 
 # called by PSGI server as body response
 # this gets called twice for every message, once to return the header,
@@ -205,20 +206,19 @@ sub mbox_all_ids {
 
 sub results_cb {
         my ($ctx) = @_;
-        my $srch = $ctx->{-inbox}->search(undef, $ctx) or return;
-        my $mset = $ctx->{mset};
+        my $over = $ctx->{-inbox}->over or return;
         while (1) {
-                while (my $mi = (($mset->items)[$ctx->{iter}++])) {
-                        my $smsg = PublicInbox::Smsg::from_mitem($mi,
-                                                                $srch) or next;
+                while (defined(my $num = shift(@{$ctx->{ids}}))) {
+                        my $smsg = $over->get_art($num) or next;
                         return $smsg;
                 }
                 # refill result set
-                $mset = $ctx->{mset} = $srch->query($ctx->{query},
-                                                        $ctx->{qopts});
+                my $srch = $ctx->{-inbox}->search(undef, $ctx) or return;
+                my $mset = $srch->query($ctx->{query}, $ctx->{qopts});
                 my $size = $mset->size or return;
                 $ctx->{qopts}->{offset} += $size;
-                $ctx->{iter} = 0;
+                my $nshard = $srch->{nshard} // 1;
+                $ctx->{ids} = [ map { mdocid($nshard, $_) } $mset->items ];
         }
 }
 
@@ -226,15 +226,16 @@ sub mbox_all {
         my ($ctx, $query) = @_;
 
         return mbox_all_ids($ctx) if $query eq '';
-        my $qopts = $ctx->{qopts} = { mset => 2 };
+        my $qopts = $ctx->{qopts} = { mset => 2 }; # order by docid
         my $srch = $ctx->{-inbox}->search or
                 return PublicInbox::WWW::need($ctx, 'Search');
-        my $mset = $ctx->{mset} = $srch->query($query, $qopts);
+        my $mset = $srch->query($query, $qopts);
         $qopts->{offset} = $mset->size or
                         return [404, [qw(Content-Type text/plain)],
                                 ["No results found\n"]];
-        $ctx->{iter} = 0;
         $ctx->{query} = $query;
+        my $nshard = $srch->{nshard} // 1;
+        $ctx->{ids} = [ map { mdocid($nshard, $_) } $mset->items ];
         require PublicInbox::MboxGz;
         PublicInbox::MboxGz::mbox_gz($ctx, \&results_cb, 'results-'.$query);
 }