diff options
author | Eric Wong (Contractor, The Linux Foundation) <e@80x24.org> | 2018-04-02 00:04:56 +0000 |
---|---|---|
committer | Eric Wong (Contractor, The Linux Foundation) <e@80x24.org> | 2018-04-02 00:05:43 +0000 |
commit | 5a44b89fd9f4ef2688b91262736b0f61095ae99c (patch) | |
tree | f5b3937f387679d277f617cbfeb6c7dc75fac717 /lib | |
parent | 87dca6d8d5988c5eb54019cca342450b0b7dd6b7 (diff) | |
download | public-inbox-5a44b89fd9f4ef2688b91262736b0f61095ae99c.tar.gz |
JOIN operations on SQLite can be disasterously slow. This reduces per-message pages with the thread overview at the bottom of those pages from over 800ms to ~60ms. In comparison, the v1 code took around 70-80ms using Xapian on my machine.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/Over.pm | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/PublicInbox/Over.pm b/lib/PublicInbox/Over.pm index c74072a2..3d285ac2 100644 --- a/lib/PublicInbox/Over.pm +++ b/lib/PublicInbox/Over.pm @@ -73,20 +73,31 @@ ORDER BY ts ASC } +sub nothing () { wantarray ? (0, []) : [] }; + sub get_thread { my ($self, $mid, $opts) = @_; my $dbh = $self->connect; - my ($tid, $sid) = $dbh->selectrow_array(<<'', undef, $mid); -SELECT tid,sid FROM over -LEFT JOIN id2num ON over.num = id2num.num -LEFT JOIN msgid ON id2num.id = msgid.id -WHERE msgid.mid = ? AND over.num > 0 -LIMIT 1 + + my $id = $dbh->selectrow_array(<<'', undef, $mid); +SELECT id FROM msgid WHERE mid = ? LIMIT 1 + + defined $id or return nothing; + + my $num = $dbh->selectrow_array(<<'', undef, $id); +SELECT num FROM id2num WHERE id = ? AND num > 0 +ORDER BY num ASC LIMIT 1 + + defined $num or return nothing; + + my ($tid, $sid) = $dbh->selectrow_array(<<'', undef, $num); +SELECT tid,sid FROM over WHERE num = ? LIMIT 1 + + defined $tid or return nothing; # $sid may be undef my $cond = 'FROM over WHERE (tid = ? OR sid = ?) AND num > 0'; my $msgs = do_get($self, <<"", $opts, $tid, $sid); -SELECT * $cond -ORDER BY ts ASC +SELECT * $cond ORDER BY ts ASC return $msgs unless wantarray; |