From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id EDF381FB0A for ; Thu, 20 Aug 2020 20:25:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 16/23] searchview: speed up search summary by ~10% Date: Thu, 20 Aug 2020 20:24:50 +0000 Message-Id: <20200820202457.21042-17-e@yhbt.net> In-Reply-To: <20200820202457.21042-1-e@yhbt.net> References: <20200820202457.21042-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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/Over.pm | 9 +++++++++ lib/PublicInbox/SearchView.pm | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/Over.pm b/lib/PublicInbox/Over.pm index 80e57e62..a055b4cd 100644 --- a/lib/PublicInbox/Over.pm +++ b/lib/PublicInbox/Over.pm @@ -104,6 +104,15 @@ ORDER BY num ASC } +sub get_all { + my $self = shift; + my $nr = scalar(@_) or return []; + my $in = '?' . (',?' x ($nr - 1)); + do_get($self, <<"", { cull => 1, limit => $nr }, @_); +SELECT num,ds,ddd FROM over WHERE num IN ($in) + +} + sub nothing () { wantarray ? (0, []) : [] }; sub get_thread { 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) {