From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) 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.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D515F1FAE7 for ; Tue, 27 Mar 2018 11:11:33 +0000 (UTC) From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Subject: [PATCH 03/11] search: reopen DB if each_smsg_by_mid fails Date: Tue, 27 Mar 2018 11:11:24 +0000 Message-Id: <20180327111132.20681-4-e@80x24.org> In-Reply-To: <20180327111132.20681-1-e@80x24.org> References: <20180327111132.20681-1-e@80x24.org> List-Id: This gives more-up-to-date data in case and allows us to avoid reopening in more places ourselves. --- lib/PublicInbox/Search.pm | 5 +++++ t/psgi_v2.t | 10 +++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 24600ee..a4e2498 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -417,6 +417,11 @@ sub each_smsg_by_mid { my $term = 'Q' . $mid; my $head = $db->postlist_begin($term); my $tail = $db->postlist_end($term); + if ($head == $tail) { + $db->reopen; + $head = $db->postlist_begin($term); + $tail = $db->postlist_end($term); + } return ($head, $tail, $db) if wantarray; for (; $head->nequal($tail); $head->inc) { my $doc_id = $head->get_docid; diff --git a/t/psgi_v2.t b/t/psgi_v2.t index 5d089db..6a2ea5b 100644 --- a/t/psgi_v2.t +++ b/t/psgi_v2.t @@ -50,12 +50,11 @@ $new_mid = PublicInbox::MID::mid_clean($mids[0]); $im->done; my $cfgpfx = "publicinbox.v2test"; -my %cfg = ( +my $cfg = { "$cfgpfx.address" => $ibx->{-primary_address}, "$cfgpfx.mainrepo" => $mainrepo, -); - -my $config = PublicInbox::Config->new({ %cfg }); +}; +my $config = PublicInbox::Config->new($cfg); my $www = PublicInbox::WWW->new($config); my ($res, $raw, @from_); test_psgi(sub { $www->call(@_) }, sub { @@ -85,9 +84,6 @@ is($warn[0], $warn[1], 'both warnings are the same'); my $third = PublicInbox::MID::mid_clean($mids[0]); $im->done; -# need to reload... -$config = PublicInbox::Config->new({ %cfg }); -$www = PublicInbox::WWW->new($config); test_psgi(sub { $www->call(@_) }, sub { my ($cb) = @_; $res = $cb->(GET("/v2test/$third/raw")); -- EW