From: Eric Wong Date: Mon, 30 Dec 2024 22:28:46 +0000 (+0000) Subject: watch: import_eml: avoid Eml dup for non-scrub case X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ab0cbb94735bc5eba6e7a258e289d104dd07982;p=thirdparty%2Fpublic-inbox.git watch: import_eml: avoid Eml dup for non-scrub case Most inboxes don't use filters, so the destructive ->scrub won't be called and we can avoid duplicating the Eml object in the common case. We'll also drop the last inbox optimization for net_cb since it's likely unnecessary given that filters are not very common. This may be more noticeable for users who map multiple inboxes to a single Maildir|IMAP|NNTP source. --- diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm index c270f5870..a37038b59 100644 --- a/lib/PublicInbox/Watch.pm +++ b/lib/PublicInbox/Watch.pm @@ -222,8 +222,10 @@ sub import_eml ($$$) { eval { my $im = _importer_for($self, $ibx); if (my $filter = $ibx->filter($im)) { - my $ret = $filter->scrub($eml) or return; + my $tmp = PublicInbox::Eml->new(\($eml->as_string)); + my $ret = $filter->scrub($tmp) or return; $ret == REJECT and return; + $eml = $tmp; } $im->add($eml, $self->{spamcheck}); }; @@ -263,9 +265,9 @@ sub _try_path ($$) { $warn_cb->($pfx, "path: $path\n", @_); }; return _remove_spam($self, $path) if $inboxes eq 'watchspam'; + my $eml = eml_from_path($path) or return; for my $ibx (@$inboxes) { - my $eml = eml_from_path($path) or next; - import_eml($self, $ibx, $eml); # $eml may be scrubbed + import_eml($self, $ibx, $eml); } 1; } @@ -323,13 +325,9 @@ sub net_cb { # NetReader::(nntp|imap)_each callback return if grep(/\Adraft\z/, @$kw); local $self->{cur_uid} = $art; # IMAP UID or NNTP article if (ref($inboxes)) { - my @ibx = @$inboxes; - my $last = pop @ibx; - for my $ibx (@ibx) { - my $tmp = PublicInbox::Eml->new(\($eml->as_string)); - import_eml($self, $ibx, $tmp); + for my $ibx (@$inboxes) { + import_eml($self, $ibx, $eml); } - import_eml($self, $last, $eml); } elsif ($inboxes eq 'watchspam') { if ($uri->scheme =~ /\Aimaps?\z/ && !grep(/\Aseen\z/, @$kw)) { return;