From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <e@80x24.org>
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN:  
X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00,
	DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,
	T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.6
Received: from localhost (dcvr.yhbt.net [127.0.0.1])
	by dcvr.yhbt.net (Postfix) with ESMTP id 9C59F1F452
	for <meta@public-inbox.org>; Sat, 11 Nov 2023 09:04:59 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org;
	s=selector1; t=1699693499;
	bh=o1Yu2GR5lE7y/D1xVqqufYo3OYAekGqbPsRSrrBQqto=;
	h=From:To:Subject:Date:In-Reply-To:References:From;
	b=Bg/3197lP5t7vpkqx47JKjblkrjJVmYyLOdtlmhKvHsfMS5O0csEUvmWPsPm9+120
	 qhnfzD0K7B/sjNI2vyFKQZBLauB2z0GjVfoMlPshwk8NQcPlvZ1lAC1EnsGuAv4zGn
	 CtgViqiIqAtY5p0iJ/OiVEYqi2KqOhyQ1tT82p/I=
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/4] learn: fix redundant ham import on dual matches
Date: Sat, 11 Nov 2023 09:04:56 +0000
Message-Id: <20231111090459.605791-2-e@80x24.org>
In-Reply-To: <20231111090459.605791-1-e@80x24.org>
References: <20231111090459.605791-1-e@80x24.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
List-Id: <meta.public-inbox.org>

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 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/script/public-inbox-learn b/script/public-inbox-learn
index 54d31cb6..8069d919 100755
--- a/script/public-inbox-learn
+++ b/script/public-inbox-learn
@@ -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});
 	}
 }