From: Eric Wong Date: Sun, 24 Jan 2021 11:46:51 +0000 (-0700) Subject: lei q: honor --no-local to force remote searches X-Git-Tag: v1.7.0~1307 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=4f50ccec41960faa703bf71b30d8ae867d0bd039;p=public-inbox.git lei q: honor --no-local to force remote searches 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). --- 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)))],