about summary refs log tree commit homepage
path: root/lib/PublicInbox/View.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-30 01:20:45 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-30 01:21:10 +0000
commitdfef0d2c34fbf21d665c40b5ad5069e9113c35c8 (patch)
treee43e0c822ee9ffb3ce122879447a754318f71d46 /lib/PublicInbox/View.pm
parent66e91d22b9899aaf5baea05b5e1652a35472b966 (diff)
downloadpublic-inbox-dfef0d2c34fbf21d665c40b5ad5069e9113c35c8.tar.gz
This saves over 400ms on my system with the full LKML
with over 2.8 million messages.
Diffstat (limited to 'lib/PublicInbox/View.pm')
-rw-r--r--lib/PublicInbox/View.pm20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index ec043433..60fc1df1 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -1069,17 +1069,31 @@ sub index_nav { # callback for WwwStream
 sub index_topics {
         my ($ctx) = @_;
         my ($off) = (($ctx->{qp}->{o} || '0') =~ /(\d+)/);
-        my $opts = { offset => $off, limit => 200 };
+        my $lim = 200;
+        my $opts = { offset => $off, limit => $lim };
 
         $ctx->{order} = [];
         my $srch = $ctx->{srch};
-        my $sres = $srch->query('', $opts);
+
+        my $qs = '';
+        # this complicated bit cuts loading time by over 400ms on my system:
+        if ($off == 0) {
+                my ($min, $max) = $ctx->{-inbox}->mm->minmax;
+                my $n = $max - $lim;
+                $n = $min if $n < $min;
+                for (; $qs eq '' && $n >= $min; --$n) {
+                        my $smsg = $srch->lookup_article($n) or next;
+                        $qs = POSIX::strftime('d:%Y%m%d..', gmtime($smsg->ts));
+                }
+        }
+
+        my $sres = $srch->query($qs, $opts);
         my $nr = scalar @{$sres->{msgs}};
         if ($nr) {
                 $sres = load_results($srch, $sres);
                 walk_thread(thread_results($ctx, $sres), $ctx, *acc_topic);
         }
-        $ctx->{-next_o} = $off+ $nr;
+        $ctx->{-next_o} = $off + $nr;
         $ctx->{-cur_o} = $off;
         PublicInbox::WwwStream->response($ctx, dump_topics($ctx), *index_nav);
 }