From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 08/21] lei: get rid of l2m_progress PktOp callback
Date: Wed, 4 Oct 2023 03:49:20 +0000 [thread overview]
Message-ID: <20231004034933.3343930-9-e@80x24.org> (raw)
In-Reply-To: <20231004034933.3343930-1-e@80x24.org>
We already have an ->incr callback we can enhance to support
multiple counters with a single request. Furthermore, we can
just flatten the object graph by storing counters directly in
the $lei object itself to reduce hash lookups.
---
lib/PublicInbox/LEI.pm | 13 ++++++-------
lib/PublicInbox/LeiConvert.pm | 7 ++++---
lib/PublicInbox/LeiTag.pm | 6 +++---
lib/PublicInbox/LeiToMail.pm | 20 ++++++++++----------
lib/PublicInbox/LeiXSearch.pm | 15 ++++-----------
t/lei-tag.t | 3 +++
6 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 3408551b..fba4edf3 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -628,8 +628,8 @@ sub pkt_op_pair {
}
sub incr {
- my ($self, $field, $nr) = @_;
- $self->{counters}->{$field} += $nr;
+ my $lei = shift;
+ while (my ($f, $n) = splice(@_, 0, 2)) { $lei->{$f} += $n }
}
sub pkt_ops {
@@ -1418,11 +1418,10 @@ sub busy { 1 } # prevent daemon-shutdown if client is connected
# can immediately reread it
sub DESTROY {
my ($self) = @_;
- if (my $counters = delete $self->{counters}) {
- for my $k (sort keys %$counters) {
- my $nr = $counters->{$k};
- $self->child_error(0, "$nr $k messages");
- }
+ for my $k (sort(grep(/\A-nr_/, keys %$self))) {
+ my $nr = $self->{$k};
+ substr($k, 0, length('-nr_'), '');
+ $self->child_error(0, "$nr $k messages");
}
$self->{1}->autoflush(1) if $self->{1};
stop_pager($self);
diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm
index 1acd4558..22aba81a 100644
--- a/lib/PublicInbox/LeiConvert.pm
+++ b/lib/PublicInbox/LeiConvert.pm
@@ -34,9 +34,10 @@ sub process_inputs { # via wq_do
$self->SUPER::process_inputs;
my $lei = $self->{lei};
delete $lei->{1};
+ my $l2m = delete $self->{l2m};
delete $self->{wcb}; # commit
- my $nr_w = delete($lei->{-nr_write}) // 0;
- my $d = (delete($lei->{-nr_seen}) // 0) - $nr_w;
+ my $nr_w = delete($l2m->{-nr_write}) // 0;
+ my $d = (delete($l2m->{-nr_seen}) // 0) - $nr_w;
$d = $d ? " ($d duplicates)" : '';
$lei->qerr("# converted $nr_w messages$d");
}
@@ -64,7 +65,7 @@ sub ipc_atfork_child {
my ($self) = @_;
my $lei = $self->{lei};
$lei->_lei_atfork_child;
- my $l2m = delete $lei->{l2m};
+ my $l2m = $lei->{l2m};
if (my $net = $lei->{net}) { # may prompt user once
$net->{mics_cached} = $net->imap_common_init($lei);
$net->{nn_cached} = $net->nntp_common_init($lei);
diff --git a/lib/PublicInbox/LeiTag.pm b/lib/PublicInbox/LeiTag.pm
index 76bd2d70..320b0355 100644
--- a/lib/PublicInbox/LeiTag.pm
+++ b/lib/PublicInbox/LeiTag.pm
@@ -15,7 +15,7 @@ sub input_eml_cb { # used by PublicInbox::LeiInput::input_fh
$self->{lei}->{sto}->wq_do('update_xvmd', $xoids, $eml,
$self->{lei}->{vmd_mod});
} else {
- ++$self->{unimported};
+ ++$self->{-nr_unimported};
}
}
@@ -40,8 +40,8 @@ sub lei_tag { # the "lei tag" method
sub note_unimported {
my ($self) = @_;
- my $n = $self->{unimported} or return;
- $self->{lei}->{pkt_op_p}->pkt_do('incr', 'unimported', $n);
+ my $n = $self->{-nr_unimported} or return;
+ $self->{lei}->{pkt_op_p}->pkt_do('incr', -nr_unimported => $n);
}
sub ipc_atfork_child {
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index b9f28ee4..f239da82 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -195,7 +195,7 @@ sub _mbox_write_cb ($$) {
sub { # for git_to_mail
my ($buf, $smsg, $eml) = @_;
$eml //= PublicInbox::Eml->new($buf);
- ++$lei->{-nr_seen};
+ ++$self->{-nr_seen};
return if $dedupe->is_dup($eml, $smsg);
$lse->xsmsg_vmd($smsg) if $lse;
$smsg->{-recent} = 1 if $set_recent;
@@ -206,7 +206,7 @@ sub _mbox_write_cb ($$) {
my $lk = $ovv->lock_for_scope;
$lei->out($$buf);
}
- ++$lei->{-nr_write};
+ ++$self->{-nr_write};
}
}
@@ -291,7 +291,7 @@ sub _maildir_write_cb ($$) {
my ($bref, $smsg, $eml) = @_;
$dst // return $lei->fail; # dst may be undef-ed in last run
- ++$lei->{-nr_seen};
+ ++$self->{-nr_seen};
return if $dedupe && $dedupe->is_dup($eml //
PublicInbox::Eml->new($$bref),
$smsg);
@@ -299,7 +299,7 @@ sub _maildir_write_cb ($$) {
my $n = _buf2maildir($dst, $bref // \($eml->as_string),
$smsg, $dir);
$lms->set_src($smsg->oidbin, $out, $n) if $lms;
- ++$lei->{-nr_write};
+ ++$self->{-nr_write};
}
}
@@ -322,7 +322,7 @@ EOM
my ($bref, $smsg, $eml) = @_;
$mic // return $lei->fail; # mic may be undef-ed in last run
- ++$lei->{-nr_seen};
+ ++$self->{-nr_seen};
return if $dedupe && $dedupe->is_dup($eml //
PublicInbox::Eml->new($$bref),
$smsg);
@@ -335,7 +335,7 @@ EOM
# imap_append returns UID if IMAP server has UIDPLUS extension
($lms && $uid =~ /\A[0-9]+\z/) and
$lms->set_src($smsg->oidbin, $$uri, $uid + 0);
- ++$lei->{-nr_write};
+ ++$self->{-nr_write};
}
}
@@ -366,10 +366,10 @@ sub _v2_write_cb ($$) {
sub { # for git_to_mail
my ($bref, $smsg, $eml) = @_;
$eml //= PublicInbox::Eml->new($bref);
- ++$lei->{-nr_seen};
+ ++$self->{-nr_seen};
return if $dedupe && $dedupe->is_dup($eml, $smsg);
$lei->{v2w}->wq_do('add', $eml); # V2Writable->add
- ++$lei->{-nr_write};
+ ++$self->{-nr_write};
}
}
@@ -796,11 +796,11 @@ sub wq_atexit_child {
local $PublicInbox::DS::in_loop = 0; # waitpid synchronously
my $lei = $self->{lei};
$lei->{ale}->git->async_wait_all;
- my ($nr_w, $nr_s) = delete(@$lei{qw(-nr_write -nr_seen)});
+ my ($nr_w, $nr_s) = delete(@$self{qw(-nr_write -nr_seen)});
delete $self->{wcb};
(($nr_w //= 0) + ($nr_s //= 0)) or return;
return if $lei->{early_mua} || !$lei->{-progress} || !$lei->{pkt_op_p};
- $lei->{pkt_op_p}->pkt_do('l2m_progress', $nr_w, $nr_s);
+ $lei->{pkt_op_p}->pkt_do('incr', -nr_write => $nr_w, -nr_seen => $nr_s)
}
# runs on a 1s timer in lei-daemon
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index 8f63149e..1caa9d06 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -155,12 +155,6 @@ sub mset_progress {
}
}
-sub l2m_progress {
- my ($lei, $nr_write, $nr_seen) = @_;
- $lei->{-nr_write} += $nr_write;
- $lei->{-nr_seen} += $nr_seen;
-}
-
sub query_one_mset { # for --threads and l2m w/o sort
my ($self, $ibxish) = @_;
local $0 = "$0 query_one_mset";
@@ -354,7 +348,6 @@ sub query_remote_mboxrd {
$self->{import_sto} = $lei->{sto} if $lei->{opt}->{'import-remote'};
for my $uri (@$uris) {
$lei->{-current_url} = $uri->as_string;
- $lei->{-nr_remote_eml} = 0;
my $start = time;
my ($q, $key) = fudge_qstr_time($lei, $uri, $qstr);
$uri->query_form(@qform, q => $q);
@@ -369,9 +362,9 @@ sub query_remote_mboxrd {
my $wait = $self->{import_sto}->wq_do('done');
}
$reap_curl->join;
+ my $nr = delete $lei->{-nr_remote_eml} // 0;
if ($? == 0) {
# don't update if no results, maybe MTA is down
- my $nr = $lei->{-nr_remote_eml};
$lei->{lss}->cfg_set($key, $start) if $key && $nr;
mset_progress($lei, $lei->{-current_url}, $nr, $nr);
next;
@@ -433,8 +426,8 @@ Error closing $lei->{ovv}->{dst}: \$!=$! \$?=$?
}
if ($lei->{-progress}) {
my $tot = $lei->{-mset_total} // 0;
- my $nr_w = $lei->{-nr_write} // 0;
- my $d = ($lei->{-nr_seen} // 0) - $nr_w;
+ my $nr_w = delete($lei->{-nr_write}) // 0;
+ my $d = (delete($lei->{-nr_seen}) // 0) - $nr_w;
my $x = "$tot matches";
$x .= ", $d duplicates" if $d;
if ($l2m) {
@@ -532,7 +525,7 @@ sub do_query {
incr_post_augment => [ \&incr_post_augment, $lei ],
'' => [ \&query_done, $lei ],
mset_progress => [ \&mset_progress, $lei ],
- l2m_progress => [ \&l2m_progress, $lei ],
+ incr => [ $lei ],
x_it => [ $lei ],
child_error => [ $lei ],
incr_start_query => [ \&incr_start_query, $lei, $self ],
diff --git a/t/lei-tag.t b/t/lei-tag.t
index 822677a7..cccf0af6 100644
--- a/t/lei-tag.t
+++ b/t/lei-tag.t
@@ -101,5 +101,8 @@ test_lei(sub {
if (0) { # TODO label+kw search w/ externals
lei_ok(qw(q L:qp), "mid:$mid", '--only', "$ro_home/t2");
}
+ lei_ok qw(tag +L:nope -F eml t/data/binary.patch);
+ like $lei_err, qr/\b1 unimported messages/, 'noted unimported'
+ or diag $lei_err;
});
done_testing;
next prev parent reply other threads:[~2023-10-04 3:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 3:49 [PATCH 00/21] lei + IPC related stuff Eric Wong
2023-10-04 3:49 ` [PATCH 01/21] lei: drop stores explicitly at daemon shutdown Eric Wong
2023-10-04 3:49 ` [PATCH 02/21] ds: hoist out close_non_busy Eric Wong
2023-10-04 3:49 ` [PATCH 03/21] ds: don't pass FD map to post_loop_do callback Eric Wong
2023-10-04 3:49 ` [PATCH 04/21] move all non-test @post_loop_do into named subs Eric Wong
2023-10-04 3:49 ` [PATCH 05/21] lei: close DirIdle (inotify) early at daemon shutdown Eric Wong
2023-10-04 3:49 ` [PATCH 06/21] input_pipe: {args} is never undefined Eric Wong
2023-10-04 3:49 ` [PATCH 07/21] lei: do_env combines fchdir and local Eric Wong
2023-10-04 3:49 ` Eric Wong [this message]
2023-10-04 3:49 ` [PATCH 09/21] t/lei_to_mail: modernize and document test Eric Wong
2023-10-04 3:49 ` [PATCH 10/21] lei: reuse PublicInbox::Config::noop Eric Wong
2023-10-04 3:49 ` [PATCH 11/21] lei: keep signals blocked on daemon shutdown Eric Wong
2023-10-04 3:49 ` [PATCH 12/21] mbox_lock: retry on EINTR and use autodie Eric Wong
2023-10-04 3:49 ` [PATCH 13/21] lock: retry on EINTR, improve error reporting Eric Wong
2023-10-04 3:49 ` [PATCH 14/21] treewide: use PublicInbox::Lock->new Eric Wong
2023-10-04 3:49 ` [PATCH 15/21] gcf2: use PublicInbox::Lock Eric Wong
2023-10-04 3:49 ` [PATCH 16/21] spawn: use autodie and PublicInbox::Lock Eric Wong
2023-10-04 3:49 ` [PATCH 17/21] xap_helper: retry flock on EINTR Eric Wong
2023-10-04 3:49 ` [PATCH 18/21] xap_helper.pm: use EINTR-aware recv_cmd Eric Wong
2023-10-04 3:49 ` [PATCH 19/21] spawn: drop checks for directory writability Eric Wong
2023-10-04 3:49 ` [PATCH 20/21] lei: document and local-ize $OPT hashref Eric Wong
2023-10-04 3:49 ` [PATCH 21/21] searchidx: fix redundant `in' in warning message Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231004034933.3343930-9-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).