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-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,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 B02731FA19 for ; Thu, 20 Aug 2020 20:24:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 09/23] www: reduce long-lived PublicInbox::Search references Date: Thu, 20 Aug 2020 20:24:43 +0000 Message-Id: <20200820202457.21042-10-e@yhbt.net> In-Reply-To: <20200820202457.21042-1-e@yhbt.net> References: <20200820202457.21042-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While this is unlikely to be a problem in current practice, keeping Xapian DBs open for long responses can interfere with free space recovery after -compact. In the future, it will interfere with inbox search grouping and lead to unexpected results. --- lib/PublicInbox/Inbox.pm | 11 ++++++++--- lib/PublicInbox/Mbox.pm | 6 +++--- lib/PublicInbox/SearchView.pm | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 267be4e3..55e546e1 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -191,14 +191,19 @@ sub mm { }; } -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 fc83a893..a83c0356 100644 --- a/lib/PublicInbox/Mbox.pm +++ b/lib/PublicInbox/Mbox.pm @@ -205,8 +205,8 @@ sub mbox_all_ids { 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 @@ sub mbox_all { 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 84c04c6c..5d77469e 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 @@ sub adump { 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; }