From 39afcefde3e9cec0120776a89977da88eb217d90 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 4 Oct 2023 03:49:20 +0000 Subject: lei: get rid of l2m_progress PktOp callback 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 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lib/PublicInbox/LEI.pm') 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); -- cgit v1.2.3-24-ge0c7