]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: reduce long-lived PublicInbox::Search references
authorEric Wong <e@yhbt.net>
Thu, 20 Aug 2020 20:24:43 +0000 (20:24 +0000)
committerEric Wong <e@yhbt.net>
Thu, 20 Aug 2020 21:11:13 +0000 (21:11 +0000)
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
lib/PublicInbox/Mbox.pm
lib/PublicInbox/SearchView.pm

index 267be4e381bad31d3cab4791f9e7c76d053726db..55e546e104f538109b95f804efb53e5a556c95ad 100644 (file)
@@ -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(<<EOF);
+`$self->{name}' search went away unexpectedly
+EOF
+               undef;
+       };
 }
 
 sub over ($) {
index fc83a893c60ab384f21061d3b2dff12edb6f365c..a83c0356d3ab7d2ac81d9fa90da520fc8e589036 100644 (file)
@@ -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)],
index 84c04c6c4713923d73f5ed5cb856e8720d19c3df..5d77469ed522bcbf14f09904275860bd876f651b 100644 (file)
@@ -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;
        }