From 5a69dffc4155c8810dd8f2f3474f7a8a5c6d16a2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 20 Aug 2020 20:24:50 +0000 Subject: searchview: speed up search summary by ~10% Instead of loading one article at-a-time from over.sqlite3, we can use SQL to mass-load IN (?,?, ...) all results with a single SQLite query. Despite SQLite being in-process and having no network latency, the reduction in SQL query executions from loading multiple rows at once speeds things up significantly. We'll keep the over->get_art optimizations from the previous commit, since it still speeds up long-lived responses, slightly. --- lib/PublicInbox/SearchView.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/PublicInbox/SearchView.pm') diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 61534c25..a3527057 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -91,22 +91,22 @@ sub mset_summary { my $pfx = ' ' x $pad; my $res = \($ctx->{-html_tip}); my $ibx = $ctx->{-inbox}; - my $over = $ibx->over; my $nshard = $ibx->search->{nshard} // 1; my $obfs_ibx = $ibx->{obfuscate} ? $ibx : undef; + my @nums = map { mdocid($nshard, $_) } $mset->items; + my %num2msg = map { $_->{num} => $_ } @{$ibx->over->get_all(@nums)}; + foreach my $m ($mset->items) { my $rank = sprintf("%${pad}d", $m->get_rank + 1); my $pct = get_pct($m); - my $num = mdocid($nshard, $m); - my $smsg = $over->get_art($num, 1); - unless ($smsg) { + my $num = shift @nums; + my $smsg = delete($num2msg{$num}) or do { eval { $m = "$m $num expired\n"; $ctx->{env}->{'psgi.errors'}->print($m); }; next; - } - PublicInbox::Smsg::psgi_cull($smsg); + }; my $s = ascii_html($smsg->{subject}); my $f = ascii_html($smsg->{from_name}); if ($obfs_ibx) { -- cgit v1.2.3-24-ge0c7