From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id AAB4E1FAEC for ; Fri, 30 Mar 2018 01:20:50 +0000 (UTC) From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Subject: [PATCH 9/9] feed: optimize query for feeds, too Date: Fri, 30 Mar 2018 01:20:48 +0000 Message-Id: <20180330012048.15985-10-e@80x24.org> In-Reply-To: <20180330012048.15985-1-e@80x24.org> References: <20180330012048.15985-1-e@80x24.org> List-Id: 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 | 2 +- lib/PublicInbox/Inbox.pm | 19 +++++++++++++++++++ lib/PublicInbox/View.pm | 17 +---------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index f2285a6..2f59f8c 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -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}; diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 90ac9eb..43cf15b 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -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; diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index c151f22..8ac405f 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -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) { -- EW