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,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 0D4EF1FA18 for ; Sun, 24 Jan 2021 11:46:56 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/9] lei q: honor --no-local to force remote searches Date: Sun, 24 Jan 2021 04:46:51 -0700 Message-Id: <20210124114655.12815-6-e@80x24.org> In-Reply-To: <20210124114655.12815-1-e@80x24.org> References: <20210124114655.12815-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This can be useful for testing remote behavior, or for augmenting local results. It'll also be possible to explicitly include/exclude externals via CLI switches (once names are decided). --- lib/PublicInbox/LeiQuery.pm | 9 ++++++++- lib/PublicInbox/LeiXSearch.pm | 2 +- t/lei.t | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm index 7713902b..953d1fc2 100644 --- a/lib/PublicInbox/LeiQuery.pm +++ b/lib/PublicInbox/LeiQuery.pm @@ -26,7 +26,14 @@ sub lei_q { my $cb = $lxs->can('prepare_external'); my $ne = $self->_externals_each($cb, $lxs); $opt->{remote} //= $ne == $lxs->remotes; - delete($lxs->{remotes}) if !$opt->{remote}; + if ($opt->{'local'}) { + delete($lxs->{remotes}) if !$opt->{remote}; + } else { + delete($lxs->{locals}); + } + } + unless ($lxs->locals || $lxs->remotes) { + return $self->fail('no local or remote inboxes to search'); } my $xj = $lxs->concurrency($opt); my $ovv = PublicInbox::LeiOverview->new($self) or return; diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index c396c597..0417db24 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -311,7 +311,7 @@ sub start_query { # always runs in main (lei-daemon) process for my $ibxish (locals($self)) { $self->wq_do('query_thread_mset', $io, $lei, $ibxish); } - } else { + } elsif (locals($self)) { $self->wq_do('query_mset', $io, $lei); } my $i = 0; diff --git a/t/lei.t b/t/lei.t index 60ca75c5..3fd1d1fe 100644 --- a/t/lei.t +++ b/t/lei.t @@ -277,6 +277,9 @@ my $test_external = sub { } ok(!$lei->('q', '-o', "$home/mbox", 's:nope'), 'fails if mbox format unspecified'); + ok(!$lei->(qw(q --no-local s:see)), '--no-local'); + is($? >> 8, 1, 'proper exit code'); + like($err, qr/no local or remote.+? to search/, 'no inbox'); my %e = ( TEST_LEI_EXTERNAL_HTTPS => 'https://public-inbox.org/meta/', TEST_LEI_EXTERNAL_ONION => $onions[int(rand(scalar(@onions)))],