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 05C941FAE9 for ; Fri, 30 Mar 2018 01:20:50 +0000 (UTC) From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Subject: [PATCH 6/9] view: speed up homepage loading time with date clamp Date: Fri, 30 Mar 2018 01:20:45 +0000 Message-Id: <20180330012048.15985-7-e@80x24.org> In-Reply-To: <20180330012048.15985-1-e@80x24.org> References: <20180330012048.15985-1-e@80x24.org> List-Id: This saves over 400ms on my system with the full LKML with over 2.8 million messages. --- lib/PublicInbox/Inbox.pm | 1 + lib/PublicInbox/View.pm | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 265360d..90ac9eb 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -132,6 +132,7 @@ sub max_git_part { sub mm { my ($self) = @_; $self->{mm} ||= eval { + require PublicInbox::Msgmap; _cleanup_later($self); my $dir = $self->{mainrepo}; if (($self->{version} || 1) >= 2) { diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index ec04343..60fc1df 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); } -- EW