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};
use PublicInbox::MID qw(mid2path);
use Devel::Peek qw(SvREFCNT);
use PublicInbox::MIME;
+use POSIX qw(strftime);
my $cleanup_timer;
eval {
$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;
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) {