diff options
author | Eric Wong <e@80x24.org> | 2016-12-03 00:24:06 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-12-03 01:48:14 +0000 |
commit | 95d4bf7aded41cb3b0040c321d315532f68633e1 (patch) | |
tree | b971609ef6fd3665d7d68352600d22ffe5b05cf8 /lib/PublicInbox/SearchView.pm | |
parent | 21f5b7a8bcd942b19475c1c0c265f39dfdf93608 (diff) | |
download | public-inbox-95d4bf7aded41cb3b0040c321d315532f68633e1.tar.gz |
This will let us stream larger Atom documents bodies without wasting too much memory and reduce the amount of round-trip requests needed to get necessary information. Hopefully clients are using streaming (SAX) parsers, too. This is the final transition in the core public-inbox code to allow migrating to a "pull"-based body streaming scheme which allows a HTTP server to respond appropriately to backpressure from slow clients.
Diffstat (limited to 'lib/PublicInbox/SearchView.pm')
-rw-r--r-- | lib/PublicInbox/SearchView.pm | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index fbba9c49..6af151a4 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -8,6 +8,7 @@ use warnings; use PublicInbox::SearchMsg; use PublicInbox::Hval qw/ascii_html/; use PublicInbox::View; +use PublicInbox::WwwAtomStream; use PublicInbox::MID qw(mid2path mid_mime mid_clean mid_escape); use Email::MIME; require PublicInbox::Git; @@ -46,7 +47,7 @@ sub sres_top_html { $cb = *noop; } else { my $x = $q->{x}; - return sub { adump($_[0], $mset, $q, $ctx) } if ($x eq 'A'); + return adump($_[0], $mset, $q, $ctx) if $x eq 'A'; $ctx->{-html_tip} = search_nav_top($mset, $q) . "\n\n"; if ($x eq 't') { @@ -213,23 +214,17 @@ sub ctx_prepare { sub adump { my ($cb, $mset, $q, $ctx) = @_; - my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]); my $ibx = $ctx->{-inbox}; - my $feed_opts = PublicInbox::Feed::get_feedopts($ctx); - my $x = ascii_html($q->{'q'}); - $x = qq{$x - search results}; - $feed_opts->{atomurl} = $feed_opts->{url} . '?'. $q->qs_html; - $feed_opts->{url} .= '?'. $q->qs_html(x => undef); - $x = PublicInbox::Feed::atom_header($feed_opts, "<title>$x</title>"); - $fh->write($x. PublicInbox::Feed::feed_updated()); - - for ($mset->items) { - $x = PublicInbox::SearchMsg->load_doc($_->get_document)->mid; - $x = mid2path($x); - my $s = PublicInbox::Feed::feed_entry($feed_opts, $x, $ibx); - $fh->write($s) if defined $s; - } - PublicInbox::Feed::end_feed($fh); + my @items = $mset->items; + $ctx->{search_query} = $q; + PublicInbox::WwwAtomStream->response($ctx, 200, sub { + while (my $x = shift @items) { + $x = PublicInbox::SearchMsg->load_doc($x->get_document); + $x = $ibx->msg_by_smsg($x) and + return Email::MIME->new($x); + } + return undef; + }); } package PublicInbox::SearchQuery; |