From 87dca6d8d5988c5eb54019cca342450b0b7dd6b7 Mon Sep 17 00:00:00 2001 From: "Eric Wong (Contractor, The Linux Foundation)" Date: Mon, 2 Apr 2018 00:04:55 +0000 Subject: www: rework query responses to avoid COUNT in SQLite In many cases, we do not care about the total number of messages. It's a rather expensive operation in SQLite (Xapian only provides an estimate). For LKML, this brings top-level /$INBOX/ loading time from ~375ms to around 60ms on my system. Days ago, this operation was taking 800-900ms(!) for me before introducing the SQLite overview DB. --- lib/PublicInbox/Over.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/Over.pm') diff --git a/lib/PublicInbox/Over.pm b/lib/PublicInbox/Over.pm index cf7a8849..c74072a2 100644 --- a/lib/PublicInbox/Over.pm +++ b/lib/PublicInbox/Over.pm @@ -88,10 +88,12 @@ LIMIT 1 SELECT * $cond ORDER BY ts ASC + return $msgs unless wantarray; + my $nr = $dbh->selectrow_array(<<"", undef, $tid, $sid); SELECT COUNT(num) $cond - { total => $nr, msgs => $msgs }; + ($nr, $msgs); } sub recent { @@ -100,10 +102,12 @@ sub recent { SELECT * FROM over WHERE num > 0 ORDER BY ts DESC + return $msgs unless wantarray; + my $nr = $self->{dbh}->selectrow_array(<<''); SELECT COUNT(num) FROM over WHERE num > 0 - { total => $nr, msgs => $msgs }; + ($nr, $msgs); } sub get_art { -- cgit v1.2.3-24-ge0c7