about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/PublicInbox/Feed.pm2
-rw-r--r--lib/PublicInbox/Inbox.pm19
-rw-r--r--lib/PublicInbox/View.pm17
3 files changed, 21 insertions, 17 deletions
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index f2285a68..2f59f8c2 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -114,7 +114,7 @@ sub recent_msgs {
                 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};
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;
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index c151f221..8ac405f2 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -1063,25 +1063,10 @@ sub index_nav { # callback for WwwStream
 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) {