]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
learn: fix redundant ham import on dual matches
authorEric Wong <e@80x24.org>
Sat, 11 Nov 2023 09:04:56 +0000 (09:04 +0000)
committerEric Wong <e@80x24.org>
Sat, 11 Nov 2023 21:20:41 +0000 (21:20 +0000)
When learning and injecting new messages ham, we want to avoid
wasting cycles importing the same message into an inbox twice
(once for the To/Cc match and once for the List-Id match).  Our
existing %seen hash turned out to be ineffective since
PublicInbox::Inbox refs get re-blessed to PublicInbox::InboxWritable.
So we stop letting class name influence the hash key for tracking by
using the reference address instead.  We can get the reference address
by performing an arithmetic operation (+ 0) instead of having to
pay the cost of importing Scalar::Util::refaddr.

script/public-inbox-learn

index 54d31cb6524be633d3545245885f9abe72c43d15..8069d919032283b70f830565428b14715c55dd15 100755 (executable)
@@ -110,12 +110,12 @@ if ($train eq 'spam' || ($train eq 'rm' && $opt{all})) {
        my %seen;
        while (my ($addr, $ibx) = each %dests) {
                next unless ref($ibx); # $ibx may be 0
-               next if $seen{"$ibx"}++;
+               next if $seen{0 + $ibx}++;
                remove_or_add($ibx, $train, $mime, $addr);
        }
        my $dests = PublicInbox::MDA->inboxes_for_list_id($pi_cfg, $mime);
        for my $ibx (@$dests) {
-               next if $seen{"$ibx"}++;
+               next if $seen{0 + $ibx}++;
                remove_or_add($ibx, $train, $mime, $ibx->{-primary_address});
        }
 }