about summary refs log tree commit homepage
path: root/lib/PublicInbox/LEI.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-04 03:49:20 +0000
committerEric Wong <e@80x24.org>2023-10-04 17:46:36 +0000
commit39afcefde3e9cec0120776a89977da88eb217d90 (patch)
tree7dd5a76a04d6245a039800199f327be4b1992a44 /lib/PublicInbox/LEI.pm
parent2bac2c5e41de98f9aa50fbf69060a3bdef54f61f (diff)
downloadpublic-inbox-39afcefde3e9cec0120776a89977da88eb217d90.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/LEI.pm')
-rw-r--r--lib/PublicInbox/LEI.pm13
1 files changed, 6 insertions, 7 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);