user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: "Eric Wong (Contractor, The Linux Foundation)" <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 9/9] feed: optimize query for feeds, too
Date: Fri, 30 Mar 2018 01:20:48 +0000	[thread overview]
Message-ID: <20180330012048.15985-10-e@80x24.org> (raw)
In-Reply-To: <20180330012048.15985-1-e@80x24.org>

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


      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 ` [PATCH 6/9] view: speed up homepage loading time with date clamp Eric Wong (Contractor, The Linux Foundation)
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 ` Eric Wong (Contractor, The Linux Foundation) [this message]

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-10-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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).