X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FView.pm;h=af287b96852be66b708bd0eff86d6064ee1773c6;hb=be4d92e74dd0b1c8de85bc08c3c522af2d8d8656;hp=cbed91639c08458987da1c3ee7bcaebcf4b8847c;hpb=b9534449ecce2c59bb4aebad6051f91c3116b187;p=public-inbox.git diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index cbed9163..af287b96 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -58,20 +58,16 @@ sub msg_page { my ($ctx) = @_; my $mid = $ctx->{mid}; my $ibx = $ctx->{-inbox}; - my ($first, $more, $head, $tail, $db); + my ($first, $more); my $smsg; if (my $srch = $ibx->search) { - $srch->retry_reopen(sub { - ($head, $tail, $db) = $srch->each_smsg_by_mid($mid); - for (; !defined($first) && $head != $tail; $head++) { - my @args = ($head, $db, $mid); - $smsg = PublicInbox::SearchMsg->get(@args); - $first = $ibx->msg_by_smsg($smsg); - } - if ($head != $tail) { - $more = [ $head, $tail, $db ]; - } - }); + my ($id, $prev); + $smsg = $srch->next_by_mid($mid, \$id, \$prev); + $first = $ibx->msg_by_smsg($smsg) if $smsg; + if ($first) { + my $next = $srch->next_by_mid($mid, \$id, \$prev); + $more = [ $id, $prev, $next ] if $next; + } return unless $first; } else { $first = $ibx->msg_by_mid($mid) or return; @@ -82,18 +78,11 @@ sub msg_page { sub msg_html_more { my ($ctx, $more, $nr) = @_; my $str = eval { - my $smsg; - my ($head, $tail, $db) = @$more; + my ($id, $prev, $smsg) = @$more; my $mid = $ctx->{mid}; - for (; !defined($smsg) && $head != $tail; $head++) { - my $m = PublicInbox::SearchMsg->get($head, $db, $mid); - $smsg = $ctx->{-inbox}->smsg_mime($m); - } - if ($head == $tail) { # done - @$more = (); - } else { - $more->[0] = $head; - } + $smsg = $ctx->{-inbox}->smsg_mime($smsg); + my $next = $ctx->{srch}->next_by_mid($mid, \$id, \$prev); + @$more = $next ? ($id, $prev, $next) : (); if ($smsg) { my $mime = $smsg->{mime}; my $upfx = '../' . mid_escape($smsg->mid) . '/'; @@ -1060,10 +1049,9 @@ sub index_nav { # callback for WwwStream pagination_footer($ctx, '.') } -sub paginate_recent ($) { - my ($ctx) = @_; +sub paginate_recent ($$) { + my ($ctx, $lim) = @_; my $t = $ctx->{qp}->{t} || ''; - my $lim = 200; # this is our window my $opts = { limit => $lim }; my ($after, $before); @@ -1105,7 +1093,7 @@ sub paginate_recent ($) { sub index_topics { my ($ctx) = @_; - my $msgs = paginate_recent($ctx); + my $msgs = paginate_recent($ctx, 200); # 200 is our window if (@$msgs) { walk_thread(thread_results($ctx, $msgs), $ctx, *acc_topic); }