about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-04-07 03:41:54 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-04-07 03:42:30 +0000
commit74b92712fa7a21fe504b9908edebcf11bb9dc170 (patch)
treecf4abdc1b8d8a64151fdcbacd095942fa227ff8e /lib/PublicInbox
parent3348ad4b3b1a0865ee58a902953165ea0f4aa4bd (diff)
downloadpublic-inbox-74b92712fa7a21fe504b9908edebcf11bb9dc170.tar.gz
This significantly improves the performance of the NNTP GROUP
command with 2.7 million messages from over 250ms to 700us.
SQLite is weird about this, but at least there's a way to
optimize it.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/Msgmap.pm10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index f5f88431..feef8ba7 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -138,10 +138,14 @@ sub num_for {
 sub minmax {
         my ($self) = @_;
         my $dbh = $self->{dbh};
-        my $sth = $self->{num_minmax} ||=
-                $dbh->prepare('SELECT MIN(num),MAX(num) FROM msgmap');
+        # breaking MIN and MAX into separate queries speeds up from 250ms
+        # to around 700us with 2.7million messages.
+        my $sth = $dbh->prepare_cached('SELECT MIN(num) FROM msgmap', undef, 1);
         $sth->execute;
-        $sth->fetchrow_array;
+        my $min = $sth->fetchrow_array;
+        $sth = $dbh->prepare_cached('SELECT MAX(num) FROM msgmap', undef, 1);
+        $sth->execute;
+        ($min, $sth->fetchrow_array);
 }
 
 sub mid_prefixes {