unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/4] "lei up --all=local" support
@ 2021-04-19 23:48 Eric Wong
  2021-04-19 23:48 ` [PATCH 1/4] lei up: fix help output and ARGV handling Eric Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eric Wong @ 2021-04-19 23:48 UTC (permalink / raw)
  To: meta

Eventually, "--all" and "--all=remote" will be supported,
but "--all=local" was relatively easy and will probably be
the most popular for latency-sensitive users.

Eric Wong (4):
  lei up: fix help output and ARGV handling
  config: favor ->get_all when possible
  lei up: more error checking for config loading
  lei up: support --all=local

 lib/PublicInbox/LEI.pm      |  7 +++-
 lib/PublicInbox/LeiQuery.pm |  2 +-
 lib/PublicInbox/LeiUp.pm    | 75 +++++++++++++++++++++++++++++++------
 lib/PublicInbox/Watch.pm    |  3 +-
 t/lei-q-save.t              |  2 +
 5 files changed, 72 insertions(+), 17 deletions(-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] lei up: fix help output and ARGV handling
  2021-04-19 23:48 [PATCH 0/4] "lei up --all=local" support Eric Wong
@ 2021-04-19 23:48 ` Eric Wong
  2021-04-19 23:48 ` [PATCH 2/4] config: favor ->get_all when possible Eric Wong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2021-04-19 23:48 UTC (permalink / raw)
  To: meta

We don't support changing search terms once "lei q --save" is
used.
---
 lib/PublicInbox/LEI.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index f641f0d9..5ee02f64 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -138,8 +138,8 @@ our %CMD = ( # sorted in order of importance/use:
 	sort|s=s reverse|r offset=i pretty jobs|j=s globoff|g augment|a
 	import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+), @c_opt,
 	opt_dash('limit|n=i', '[0-9]+') ],
-'up' => [ 'SEARCH_TERMS...', 'update saved search',
-	qw(jobs|j=s lock=s@ alert=s@ mua=s verbose|v+), @c_opt ],
+'up' => [ 'OUTPUT', 'update saved search',
+	qw(jobs|j=s lock=s@ alert=s@ mua=s verbose|v+ all), @c_opt ],
 
 'blob' => [ 'OID', 'show a git blob, reconstructing from mail if necessary',
 	qw(git-dir=s@ cwd! verbose|v+ mail! oid-a|A=s path-a|a=s path-b|b=s),

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] config: favor ->get_all when possible
  2021-04-19 23:48 [PATCH 0/4] "lei up --all=local" support Eric Wong
  2021-04-19 23:48 ` [PATCH 1/4] lei up: fix help output and ARGV handling Eric Wong
@ 2021-04-19 23:48 ` Eric Wong
  2021-04-19 23:49 ` [PATCH 3/4] lei up: more error checking for config loading Eric Wong
  2021-04-19 23:49 ` [PATCH 4/4] lei up: support --all=local Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2021-04-19 23:48 UTC (permalink / raw)
  To: meta

It's slightly less code.
---
 lib/PublicInbox/LeiUp.pm | 5 ++---
 lib/PublicInbox/Watch.pm | 3 +--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm
index 23c5c606..63a7f996 100644
--- a/lib/PublicInbox/LeiUp.pm
+++ b/lib/PublicInbox/LeiUp.pm
@@ -25,10 +25,9 @@ sub lei_up {
 	$lei->{opt}->{output} = $lss->{-cfg}->{'lei.q.output'} //
 		return $lei->fail("lei.q.output unset in $lss->{-f}");
 
-	my $to_avref = $lss->{-cfg}->can('_array');
 	for my $k (qw(only include exclude)) {
-		my $v = $lss->{-cfg}->{"lei.q.$k"} // next;
-		$lei->{opt}->{$k} = $to_avref->($v);
+		my $v = $lss->{-cfg}->get_all("lei.q.$k") // next;
+		$lei->{opt}->{$k} = $v;
 	}
 	for my $k (qw(external local remote
 			import-remote import-before threads)) {
diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm
index 05956cbb..86dae91f 100644
--- a/lib/PublicInbox/Watch.pm
+++ b/lib/PublicInbox/Watch.pm
@@ -53,8 +53,7 @@ sub new {
 	# indefinitely...
 	foreach my $pfx (qw(publicinboxwatch publicinboxlearn)) {
 		my $k = "$pfx.watchspam";
-		defined(my $dirs = $cfg->{$k}) or next;
-		$dirs = PublicInbox::Config::_array($dirs);
+		my $dirs = $cfg->get_all($k) // next;
 		for my $dir (@$dirs) {
 			my $uri;
 			if (is_maildir($dir)) {

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] lei up: more error checking for config loading
  2021-04-19 23:48 [PATCH 0/4] "lei up --all=local" support Eric Wong
  2021-04-19 23:48 ` [PATCH 1/4] lei up: fix help output and ARGV handling Eric Wong
  2021-04-19 23:48 ` [PATCH 2/4] config: favor ->get_all when possible Eric Wong
@ 2021-04-19 23:49 ` Eric Wong
  2021-04-19 23:49 ` [PATCH 4/4] lei up: support --all=local Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2021-04-19 23:49 UTC (permalink / raw)
  To: meta

We'll support editing the saved search config file, so user
errors may happen and we need to throw sensible errors in that
case.
---
 lib/PublicInbox/LeiUp.pm | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm
index 63a7f996..e80ccf57 100644
--- a/lib/PublicInbox/LeiUp.pm
+++ b/lib/PublicInbox/LeiUp.pm
@@ -14,24 +14,27 @@ sub lei_up {
 	my $lss = PublicInbox::LeiSavedSearch->up($lei, $out) or return;
 	my $mset_opt = $lei->{mset_opt} = { relevance => -2 };
 	$mset_opt->{limit} = $lei->{opt}->{limit} // 10000;
+	my $f = $lss->{'-f'};
 	my $q = $mset_opt->{q_raw} = $lss->{-cfg}->{'lei.q'} //
-				return $lei->fail("lei.q unset in $lss->{-f}");
+				return $lei->fail("lei.q unset in $f");
 	my $lse = $lei->{lse} // die 'BUG: {lse} missing';
 	if (ref($q)) {
 		$mset_opt->{qstr} = $lse->query_argv_to_string($lse->git, $q);
 	} else {
 		$lse->query_approxidate($lse->git, $mset_opt->{qstr} = $q);
 	}
-	$lei->{opt}->{output} = $lss->{-cfg}->{'lei.q.output'} //
-		return $lei->fail("lei.q.output unset in $lss->{-f}");
-
+	my $o = $lei->{opt}->{output} = $lss->{-cfg}->{'lei.q.output'} //
+		return $lei->fail("lei.q.output unset in $f");
+	ref($o) and return $lei->fail("multiple values of lei.q.output in $f");
 	for my $k (qw(only include exclude)) {
 		my $v = $lss->{-cfg}->get_all("lei.q.$k") // next;
 		$lei->{opt}->{$k} = $v;
 	}
 	for my $k (qw(external local remote
 			import-remote import-before threads)) {
-		my $v = $lss->{-cfg}->{"lei.q.$k"} // next;
+		my $c = "lei.q.$k";
+		my $v = $lss->{-cfg}->{$c} // next;
+		ref($v) and return $lei->fail("multiple values of $c in $f");
 		$lei->{opt}->{$k} = $v;
 	}
 	$lei->{lss} = $lss; # for LeiOverview->new

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] lei up: support --all=local
  2021-04-19 23:48 [PATCH 0/4] "lei up --all=local" support Eric Wong
                   ` (2 preceding siblings ...)
  2021-04-19 23:49 ` [PATCH 3/4] lei up: more error checking for config loading Eric Wong
@ 2021-04-19 23:49 ` Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2021-04-19 23:49 UTC (permalink / raw)
  To: meta

Users may wish to update several saved searches at once.  We can
support parallel updates in lei-daemon so users won't have to do
it themselves via xargs or similar.

Supporting IMAP outputs would be significantly more involved
since we'd have to pre-authenticate for every single IMAP
output before entering the redispatch loop.
---
 lib/PublicInbox/LEI.pm      |  7 +++--
 lib/PublicInbox/LeiQuery.pm |  2 +-
 lib/PublicInbox/LeiUp.pm    | 59 +++++++++++++++++++++++++++++++++----
 t/lei-q-save.t              |  2 ++
 4 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 5ee02f64..c0385eb5 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -138,8 +138,9 @@ our %CMD = ( # sorted in order of importance/use:
 	sort|s=s reverse|r offset=i pretty jobs|j=s globoff|g augment|a
 	import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+), @c_opt,
 	opt_dash('limit|n=i', '[0-9]+') ],
-'up' => [ 'OUTPUT', 'update saved search',
-	qw(jobs|j=s lock=s@ alert=s@ mua=s verbose|v+ all), @c_opt ],
+
+'up' => [ 'OUTPUT|--all', 'update saved search',
+	qw(jobs|j=s lock=s@ alert=s@ mua=s verbose|v+ all:s), @c_opt ],
 
 'blob' => [ 'OID', 'show a git blob, reconstructing from mail if necessary',
 	qw(git-dir=s@ cwd! verbose|v+ mail! oid-a|A=s path-a|a=s path-b|b=s),
@@ -331,6 +332,8 @@ my %OPTDESC = (
 'remote' => 'limit operations to those requiring network access',
 'remote!' => 'prevent operations requiring network access',
 
+'all:s	up' => ['local', 'update all (local) saved searches' ],
+
 'mid=s' => 'specify the Message-ID of a message',
 'oid=s' => 'specify the git object ID of a message',
 
diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm
index 385ba0a9..4099b26c 100644
--- a/lib/PublicInbox/LeiQuery.pm
+++ b/lib/PublicInbox/LeiQuery.pm
@@ -14,6 +14,7 @@ sub prep_ext { # externals_each callback
 
 sub _start_query { # used by "lei q" and "lei up"
 	my ($self) = @_;
+	require PublicInbox::LeiOverview;
 	PublicInbox::LeiOverview->new($self) or return;
 	my $opt = $self->{opt};
 	my ($xj, $mj) = split(/,/, $opt->{jobs} // '');
@@ -117,7 +118,6 @@ sub lxs_prepare {
 # the main "lei q SEARCH_TERMS" method
 sub lei_q {
 	my ($self, @argv) = @_;
-	require PublicInbox::LeiOverview;
 	PublicInbox::Config->json; # preload before forking
 	my $lxs = lxs_prepare($self) or return;
 	$self->ale->refresh_externals($lxs);
diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm
index e80ccf57..0fb9698b 100644
--- a/lib/PublicInbox/LeiUp.pm
+++ b/lib/PublicInbox/LeiUp.pm
@@ -6,15 +6,14 @@ package PublicInbox::LeiUp;
 use strict;
 use v5.10.1;
 use PublicInbox::LeiSavedSearch;
-use PublicInbox::LeiOverview;
+use parent qw(PublicInbox::IPC);
 
-sub lei_up {
+sub up1 ($$) {
 	my ($lei, $out) = @_;
-	$lei->{lse} = $lei->_lei_store(1)->search;
 	my $lss = PublicInbox::LeiSavedSearch->up($lei, $out) or return;
+	my $f = $lss->{'-f'};
 	my $mset_opt = $lei->{mset_opt} = { relevance => -2 };
 	$mset_opt->{limit} = $lei->{opt}->{limit} // 10000;
-	my $f = $lss->{'-f'};
 	my $q = $mset_opt->{q_raw} = $lss->{-cfg}->{'lei.q'} //
 				return $lei->fail("lei.q unset in $f");
 	my $lse = $lei->{lse} // die 'BUG: {lse} missing';
@@ -40,10 +39,60 @@ sub lei_up {
 	$lei->{lss} = $lss; # for LeiOverview->new
 	my $lxs = $lei->lxs_prepare or return;
 	$lei->ale->refresh_externals($lxs);
-	$lei->{opt}->{save} = -1;
 	$lei->_start_query;
 }
 
+sub up1_redispatch {
+	my ($lei, $out, $op_p) = @_;
+	my $l = bless { %$lei }, ref($lei);
+	$l->{opt} = { %{$l->{opt}} };
+	delete $l->{sock};
+	$l->{''} = $op_p; # daemon only
+	eval {
+		$l->qerr("# updating $out");
+		up1($l, $out);
+		$l->qerr("# $out done");
+	};
+	$l->err($@) if $@;
+}
+
+sub lei_up {
+	my ($lei, $out) = @_;
+	$lei->{lse} = $lei->_lei_store(1)->search;
+	my $opt = $lei->{opt};
+	$opt->{save} = -1;
+	if (defined $opt->{all}) {
+		length($opt->{mua}//'') and return
+			$lei->fail('--all and --mua= are incompatible');
+
+		# supporting IMAP outputs is more involved due to
+		# git-credential prompts.  TODO: add this in 1.8
+		$opt->{all} eq 'local' or return
+			$lei->fail('only --all=local works at the moment');
+		my @all = PublicInbox::LeiSavedSearch::list($lei);
+		my @local = grep(!m!\Aimaps?://!i, @all);
+		$lei->_lei_store->write_prepare($lei); # share early
+		if ($lei->{oneshot}) { # synchronous
+			up1_redispatch($lei, $_) for @local;
+		} else {
+			# daemon mode, re-dispatch into our event loop w/o
+			# creating an extra fork-level
+			require PublicInbox::DS;
+			require PublicInbox::PktOp;
+			my ($op_c, $op_p) = PublicInbox::PktOp->pair;
+			for my $o (@local) {
+				PublicInbox::DS::requeue(sub {
+					up1_redispatch($lei, $o, $op_p);
+				});
+			}
+			$lei->event_step_init;
+			$op_c->{ops} = { '' => [$lei->can('dclose'), $lei] };
+		}
+	} else {
+		up1($lei, $out);
+	}
+}
+
 sub _complete_up {
 	my ($lei, @argv) = @_;
 	my ($cur, $re) = $lei->complete_url_common(\@argv);
diff --git a/t/lei-q-save.t b/t/lei-q-save.t
index c0c74581..58342171 100644
--- a/t/lei-q-save.t
+++ b/t/lei-q-save.t
@@ -108,5 +108,7 @@ test_lei(sub {
 	$mb = do { local $/; <$mb> };
 	like($mb, qr/pre-existing/, 'pre-existing message preserved w/ -a');
 	like($mb, qr/<qp\@example\.com>/, 'new result written w/ -a');
+
+	lei_ok(qw(up --all=local));
 });
 done_testing;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-19 23:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 23:48 [PATCH 0/4] "lei up --all=local" support Eric Wong
2021-04-19 23:48 ` [PATCH 1/4] lei up: fix help output and ARGV handling Eric Wong
2021-04-19 23:48 ` [PATCH 2/4] config: favor ->get_all when possible Eric Wong
2021-04-19 23:49 ` [PATCH 3/4] lei up: more error checking for config loading Eric Wong
2021-04-19 23:49 ` [PATCH 4/4] lei up: support --all=local Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).