From 55263c56cf41c87f8977cd6a6be65ac07b5cea87 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 5 Jul 2020 23:27:39 +0000 Subject: wwwstream: reduce blob fetch paths for ->getline This will make it easier to support asynchronous blob retrievals. The `$ctx->{nr}' counter is no longer implicitly supplied since many users didn't care for it, so stack overhead is slightly reduced. --- lib/PublicInbox/SearchView.pm | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'lib/PublicInbox/SearchView.pm') diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 71c3ae70..eeebdfa3 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -10,12 +10,11 @@ use PublicInbox::Smsg; use PublicInbox::Hval qw(ascii_html obfuscate_addrs mid_href); use PublicInbox::View; use PublicInbox::WwwAtomStream; +use PublicInbox::WwwStream qw(html_oneshot); use PublicInbox::SearchThread; our $LIM = 200; my %rmap_inc; -my $noop = sub {}; - sub mbox_results { my ($ctx) = @_; my $q = PublicInbox::SearchQuery->new($ctx->{qp}); @@ -48,7 +47,7 @@ sub sres_top_html { relevance => $q->{r}, asc => $asc, }; - my ($mset, $total, $err, $cb); + my ($mset, $total, $err, $html); retry: eval { $mset = $srch->query($query, $opts); @@ -58,8 +57,7 @@ retry: ctx_prepare($q, $ctx); if ($err) { $code = 400; - $ctx->{-html_tip} = '
'.err_txt($ctx, $err).'

'; - $cb = $noop; + $html = '
'.err_txt($ctx, $err).'

'; } elsif ($total == 0) { if (defined($ctx->{-uxs_retried})) { # undo retry damage: @@ -70,19 +68,16 @@ retry: goto retry; } $code = 404; - $ctx->{-html_tip} = "
\n[No results found]

"; - $cb = $noop; + $html = "
\n[No results found]

"; } else { return adump($_[0], $mset, $q, $ctx) if $x eq 'A'; $ctx->{-html_tip} = search_nav_top($mset, $q, $ctx); - if ($x eq 't') { - $cb = mset_thread($ctx, $mset, $q); - } else { - $cb = mset_summary($ctx, $mset, $q); - } + return mset_thread($ctx, $mset, $q) if $x eq 't'; + mset_summary($ctx, $mset, $q); # appends to {-html_tip} + $html = ''; } - PublicInbox::WwwStream::response($ctx, $code, $cb); + html_oneshot($ctx, $code); } # display non-nested search results similar to what users expect from @@ -122,7 +117,7 @@ sub mset_summary { $$res .= "$pfx - by $f @ $date UTC [$pct%]\n\n"; } $$res .= search_nav_bot($mset, $q); - $noop; + undef; } # shorten "/full/path/to/Foo/Bar.pm" to "Foo/Bar.pm" so error @@ -292,12 +287,13 @@ sub mset_thread { @$msgs = reverse @$msgs if $r; $ctx->{msgs} = $msgs; - \&mset_thread_i; + PublicInbox::WwwStream::response($ctx, 200, \&mset_thread_i); } # callback for PublicInbox::WwwStream::getline sub mset_thread_i { - my ($nr, $ctx) = @_; + my ($ctx) = @_; + return $ctx->html_top if exists $ctx->{-html_tip}; my $msgs = $ctx->{msgs} or return; while (my $smsg = pop @$msgs) { my $eml = $ctx->{-inbox}->smsg_eml($smsg) or next; -- cgit v1.2.3-24-ge0c7