From: Eric Wong (Contractor, The Linux Foundation) Date: Fri, 30 Mar 2018 01:20:45 +0000 (+0000) Subject: view: speed up homepage loading time with date clamp X-Git-Tag: v1.1.0-pre1~91 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=dfef0d2c34fbf21d665c40b5ad5069e9113c35c8 view: speed up homepage loading time with date clamp This saves over 400ms on my system with the full LKML with over 2.8 million messages. --- diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 265360d9..90ac9ebb 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 ec043433..60fc1df1 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); }