From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 32BC31FC6D for ; Wed, 25 Dec 2019 07:51:09 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 23/30] searchview: pass named subs to Www*Stream Date: Wed, 25 Dec 2019 07:50:57 +0000 Message-Id: <20191225075104.22184-24-e@80x24.org> In-Reply-To: <20191225075104.22184-1-e@80x24.org> References: <20191225075104.22184-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Both WwwStream and WwwAtomStream ->response pass the WWW $ctx to the callback nowadays, so we can pass named subs to them. --- lib/PublicInbox/SearchView.pm | 55 ++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 7afb0754..6aa815ca 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -275,8 +275,7 @@ sub get_pct ($) { sub mset_thread { my ($ctx, $mset, $q) = @_; my %pct; - my $ibx = $ctx->{-inbox}; - my $msgs = $ibx->search->retry_reopen(sub { [ map { + my $msgs = $ctx->{-inbox}->search->retry_reopen(sub { [ map { my $i = $_; my $smsg = PublicInbox::SearchMsg->load_doc($i->get_document); $pct{$smsg->mid} = get_pct($i); @@ -303,19 +302,21 @@ sub mset_thread { *PublicInbox::View::pre_thread); @$msgs = reverse @$msgs if $r; - sub { - return unless $msgs; - my $smsg; - while (my $m = pop @$msgs) { - $smsg = $ibx->smsg_mime($m) and last; - } - if ($smsg) { - return PublicInbox::View::index_entry($smsg, $ctx, - scalar @$msgs); - } - $msgs = undef; - $skel .= "\n"; - }; + $ctx->{msgs} = $msgs; + \&mset_thread_i; +} + +# callback for PublicInbox::WwwStream::getline +sub mset_thread_i { + my ($nr, $ctx) = @_; + my $msgs = $ctx->{msgs} or return; + while (my $smsg = pop @$msgs) { + $ctx->{-inbox}->smsg_mime($smsg) or next; + return PublicInbox::View::index_entry($smsg, $ctx, + scalar @$msgs); + } + my ($skel) = delete @$ctx{qw(dst msgs)}; + $$skel .= "\n"; } sub ctx_prepare { @@ -337,17 +338,19 @@ sub ctx_prepare { sub adump { my ($cb, $mset, $q, $ctx) = @_; - my $ibx = $ctx->{-inbox}; - my @items = $mset->items; - $ctx->{search_query} = $q; - my $srch = $ibx->search; - PublicInbox::WwwAtomStream->response($ctx, 200, sub { - while (my $x = shift @items) { - $x = load_doc_retry($srch, $x); - $x = $ibx->smsg_mime($x) and return $x; - } - return undef; - }); + $ctx->{items} = [ $mset->items ]; + $ctx->{search_query} = $q; # used by WwwAtomStream::atom_header + $ctx->{srch} = $ctx->{-inbox}->search; + PublicInbox::WwwAtomStream->response($ctx, 200, \&adump_i); +} + +# callback for PublicInbox::WwwAtomStream::getline +sub adump_i { + my ($ctx) = @_; + while (my $mi = shift @{$ctx->{items}}) { + my $smsg = load_doc_retry($ctx->{srch}, $mi) or next; + $ctx->{-inbox}->smsg_mime($smsg) and return $smsg; + } } package PublicInbox::SearchQuery;