]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchview: convert nested and Atom display to over.sqlite3
authorEric Wong <e@yhbt.net>
Thu, 20 Aug 2020 20:24:51 +0000 (20:24 +0000)
committerEric Wong <e@yhbt.net>
Thu, 20 Aug 2020 21:11:19 +0000 (21:11 +0000)
git blob retrieval dominates on these, "&x=t" (nested) is
roughly the same due to increased overhead for ->get_percent
storage balancing out the mass-loading from SQLite.

Atom "&x=A" is sped up slightly and uses less memory in the
long-lived response.

lib/PublicInbox/SearchView.pm

index a3527057d7bbcc072401a80f0cc8bde0b5962e43..ef1b9767867c02cee0bdec964d4ca76261cd5077 100644 (file)
@@ -255,20 +255,13 @@ sub get_pct ($) {
        $n > 99 ? 99 : $n;
 }
 
-sub load_msgs {
-       my ($mset) = @_;
-       [ map {
-               my $mi = $_;
-               my $smsg = PublicInbox::Smsg::from_mitem($mi);
-               $smsg->{pct} = get_pct($mi);
-               $smsg;
-       } ($mset->items) ]
-}
-
 sub mset_thread {
        my ($ctx, $mset, $q) = @_;
        my $ibx = $ctx->{-inbox};
-       my $msgs = $ibx->search->retry_reopen(\&load_msgs, $mset);
+       my $nshard = $ibx->search->{nshard} // 1;
+       my %pct = map { mdocid($nshard, $_) => get_pct($_) } $mset->items;
+       my $msgs = $ibx->over->get_all(keys %pct);
+       $_->{pct} = $pct{$_->{num}} for @$msgs;
        my $r = $q->{r};
        my $rootset = PublicInbox::SearchThread::thread($msgs,
                $r ? \&sort_relevance : \&PublicInbox::View::sort_ds,
@@ -323,7 +316,8 @@ sub ctx_prepare {
 
 sub adump {
        my ($cb, $mset, $q, $ctx) = @_;
-       $ctx->{items} = [ $mset->items ];
+       my $nshard = $ctx->{-inbox}->search->{nshard} // 1;
+       $ctx->{ids} = [ map { mdocid($nshard, $_) } $mset->items ];
        $ctx->{search_query} = $q; # used by WwwAtomStream::atom_header
        PublicInbox::WwwAtomStream->response($ctx, 200, \&adump_i);
 }
@@ -331,11 +325,8 @@ sub adump {
 # callback for PublicInbox::WwwAtomStream::getline
 sub adump_i {
        my ($ctx) = @_;
-       while (my $mi = shift @{$ctx->{items}}) {
-               my $srch = $ctx->{-inbox}->search(undef, $ctx) or return;
-               my $smsg = eval {
-                       PublicInbox::Smsg::from_mitem($mi, $srch);
-               } or next;
+       while (my $num = shift @{$ctx->{ids}}) {
+               my $smsg = eval { $ctx->{-inbox}->over->get_art($num) } or next;
                return $smsg;
        }
 }