about summary refs log tree commit homepage
path: root/lib/PublicInbox/Inbox.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-30 01:20:48 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-30 01:21:13 +0000
commitd012bfbedf10b925433d1b7bd823370347371e33 (patch)
treedd7b84c9fcd216b142b6375bf1f1071e6ba59e11 /lib/PublicInbox/Inbox.pm
parentf886760b1b5c79181143743814a576a8fa5cf4d9 (diff)
downloadpublic-inbox-d012bfbedf10b925433d1b7bd823370347371e33.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/Inbox.pm')
-rw-r--r--lib/PublicInbox/Inbox.pm19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 90ac9ebb..43cf15ba 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;