unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: "Eric Wong (Contractor, The Linux Foundation)" <e@80x24.org>
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	[thread overview]
Message-ID: <20180330012048.15985-7-e@80x24.org> (raw)
In-Reply-To: <20180330012048.15985-1-e@80x24.org>

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


  parent reply	other threads:[~2018-03-30  1:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-30  1:20 [PATCH 0/9] minor tweaks and fixes Eric Wong (Contractor, The Linux Foundation)
2018-03-30  1:20 ` [PATCH 1/9] search: warn on reopens and die on total failure Eric Wong (Contractor, The Linux Foundation)
2018-03-30  1:20 ` [PATCH 2/9] v2writable: allow gaps in git partitions Eric Wong (Contractor, The Linux Foundation)
2018-03-30  1:20 ` [PATCH 3/9] v2writable: convert some fatal reindex errors to warnings Eric Wong (Contractor, The Linux Foundation)
2018-03-30  1:20 ` [PATCH 4/9] wwwstream: flesh out clone instructions for v2 Eric Wong (Contractor, The Linux Foundation)
2018-03-30  1:20 ` [PATCH 5/9] v2writable: go backwards through alternate Message-IDs Eric Wong (Contractor, The Linux Foundation)
2018-03-30  1:20 ` Eric Wong (Contractor, The Linux Foundation) [this message]
2018-03-30  1:20 ` [PATCH 7/9] view: drop load_results Eric Wong (Contractor, The Linux Foundation)
2018-03-30  1:20 ` [PATCH 8/9] msgtime: parse 3-digit years properly Eric Wong (Contractor, The Linux Foundation)
2018-03-30  1:20 ` [PATCH 9/9] feed: optimize query for feeds, too Eric Wong (Contractor, The Linux Foundation)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180330012048.15985-7-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).