]> Sergey Matveev's repositories - public-inbox.git/commitdiff
feed: optimize query for feeds, too
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Fri, 30 Mar 2018 01:20:48 +0000 (01:20 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Fri, 30 Mar 2018 01:21:13 +0000 (01:21 +0000)
This is a smaller improvement than the landing /$INBOX/ page
because full message bodies are shown; but still saves around
100ms for my system with LKML.

lib/PublicInbox/Feed.pm
lib/PublicInbox/Inbox.pm
lib/PublicInbox/View.pm

index f2285a686d22f2a019da6c859d52ff84f860c962..2f59f8c2939b258d0c028c07a323cbb85380fcfb 100644 (file)
@@ -114,7 +114,7 @@ sub recent_msgs {
                my $o = $qp ? $qp->{o} : 0;
                $o += 0;
                $o = 0 if $o < 0;
-               my $res = $srch->query('', { limit => $max, offset => $o });
+               my $res = $ibx->recent({ limit => $max, offset => $o });
                my $next = $o + $max;
                $ctx->{next_page} = "o=$next" if $res->{total} >= $next;
                return $res->{msgs};
index 90ac9ebb7c31628a292ec69647399969b1adf2fe..43cf15baaa0c2beddb0fe3108b61fd74a7c8af0b 100644 (file)
@@ -9,6 +9,7 @@ use PublicInbox::Git;
 use PublicInbox::MID qw(mid2path);
 use Devel::Peek qw(SvREFCNT);
 use PublicInbox::MIME;
+use POSIX qw(strftime);
 
 my $cleanup_timer;
 eval {
@@ -316,4 +317,22 @@ sub msg_by_mid ($$;$) {
        $smsg ? msg_by_smsg($self, $smsg, $ref) : undef;
 }
 
+sub recent {
+       my ($self, $opts) = @_;
+       my $qs = '';
+       my $srch = search($self);
+       if (!$opts->{offset}) {
+               # this complicated bit cuts /$INBOX/ loading time by
+               # over 400ms on my system:
+               my ($min, $max) = mm($self)->minmax;
+               my $n = $max - $opts->{limit};
+               $n = $min if $n < $min;
+               for (; $qs eq '' && $n >= $min; --$n) {
+                       my $smsg = $srch->lookup_article($n) or next;
+                       $qs = strftime('d:%Y%m%d..', gmtime($smsg->ts));
+               }
+       }
+       $srch->query($qs, $opts);
+}
+
 1;
index c151f221cc9ea1667fafd20253157c1bc9d7c7a5..8ac405f2b73cd78ce91b8e308738898694ac732b 100644 (file)
@@ -1063,25 +1063,10 @@ sub index_nav { # callback for WwwStream
 sub index_topics {
        my ($ctx) = @_;
        my ($off) = (($ctx->{qp}->{o} || '0') =~ /(\d+)/);
-       my $lim = 200;
-       my $opts = { offset => $off, limit => $lim };
 
        $ctx->{order} = [];
        my $srch = $ctx->{srch};
-
-       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 $sres = $ctx->{-inbox}->recent({offset => $off, limit => 200 });
        $sres = $sres->{msgs};
        my $nr = scalar @$sres;
        if ($nr) {