]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Inbox.pm
feed: optimize query for feeds, too
[public-inbox.git] / lib / PublicInbox / Inbox.pm
index 90ac9ebb7c31628a292ec69647399969b1adf2fe..43cf15baaa0c2beddb0fe3108b61fd74a7c8af0b 100644 (file)
@@ -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;