X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FInbox.pm;h=43cf15baaa0c2beddb0fe3108b61fd74a7c8af0b;hb=d012bfbedf10b925433d1b7bd823370347371e33;hp=265360d94b6e150c0fa0fc313d0315978a7b06fd;hpb=34d6aff1ca223521d8137f642a58db077ab70df0;p=public-inbox.git diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 265360d9..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 { @@ -132,6 +133,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) { @@ -315,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;