lib/PublicInbox/Inbox.pm | 11 ++++++++--- lib/PublicInbox/Mbox.pm | 6 +++--- lib/PublicInbox/SearchView.pm | 4 ++-- diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 267be4e381bad31d3cab4791f9e7c76d053726db..55e546e104f538109b95f804efb53e5a556c95ad 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -191,14 +191,19 @@ } }; } -sub search ($;$) { - my ($self, $over_only) = @_; +sub search ($;$$) { + my ($self, $over_only, $ctx) = @_; my $srch = $self->{search} ||= eval { _cleanup_later($self); require PublicInbox::Search; PublicInbox::Search->new($self); }; - ($over_only || eval { $srch->xdb }) ? $srch : undef; + ($over_only || eval { $srch->xdb }) ? $srch : do { + $ctx and $ctx->{env}->{'psgi.errors'}->print(<{name}' search went away unexpectedly +EOF + undef; + }; } sub over ($) { diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm index fc83a893c60ab384f21061d3b2dff12edb6f365c..a83c0356d3ab7d2ac81d9fa90da520fc8e589036 100644 --- a/lib/PublicInbox/Mbox.pm +++ b/lib/PublicInbox/Mbox.pm @@ -205,8 +205,8 @@ } sub results_cb { my ($ctx) = @_; + my $srch = $ctx->{-inbox}->search(undef, $ctx) or return; my $mset = $ctx->{mset}; - my $srch = $ctx->{srch}; while (1) { while (my $mi = (($mset->items)[$ctx->{iter}++])) { my $smsg = PublicInbox::Smsg::from_mitem($mi, @@ -227,8 +227,8 @@ my ($ctx, $query) = @_; return mbox_all_ids($ctx) if $query eq ''; my $qopts = $ctx->{qopts} = { mset => 2 }; - my $srch = $ctx->{srch} = $ctx->{-inbox}->search or - return PublicInbox::WWW::need($ctx, 'Search');; + my $srch = $ctx->{-inbox}->search or + return PublicInbox::WWW::need($ctx, 'Search'); my $mset = $ctx->{mset} = $srch->query($query, $qopts); $qopts->{offset} = $mset->size or return [404, [qw(Content-Type text/plain)], diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 84c04c6c4713923d73f5ed5cb856e8720d19c3df..5d77469ed522bcbf14f09904275860bd876f651b 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -321,7 +321,6 @@ sub adump { my ($cb, $mset, $q, $ctx) = @_; $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); } @@ -329,8 +328,9 @@ # callback for PublicInbox::WwwAtomStream::getline sub adump_i { my ($ctx) = @_; while (my $mi = shift @{$ctx->{items}}) { + my $srch = $ctx->{-inbox}->search(undef, $ctx) or return; my $smsg = eval { - PublicInbox::Smsg::from_mitem($mi, $ctx->{srch}); + PublicInbox::Smsg::from_mitem($mi, $srch); } or next; return $smsg; }