lib/PublicInbox/Import.pm | 3 +++ lib/PublicInbox/V2Writable.pm | 3 +++ lib/PublicInbox/Watch.pm | 31 +++++++++++++++++++++++++------ diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 700b40262e36d6eae460d12639106b6c2529062c..ee5ca2ea11b4f383e514ecdf117ac1dabe2c14c1 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -461,6 +461,9 @@ close $fh or die "close $f: $!"; } } +# true if locked and active +sub active { !!$_[0]->{out} } + sub done { my ($self) = @_; my $w = delete $self->{out} or return; diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index f2288904638e98e147af30bc68a1678a5dcda7f7..553dd839f39a9a56227e8a092d55e791ca54b2e0 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -655,6 +655,9 @@ # and read-only ops. Order of data importance is: git > SQLite > Xapian # public sub barrier { checkpoint($_[0], 1) }; +# true if locked and active +sub active { !!$_[0]->{im} } + # public sub done { my ($self) = @_; diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm index 5f78613961db1058506b8193c4ea7bd55c0522f3..0bb92d0a9055703233b7af5cafe53bdfa0232e2f 100644 --- a/lib/PublicInbox/Watch.pm +++ b/lib/PublicInbox/Watch.pm @@ -134,14 +134,33 @@ sub remove_eml_i { # each_inbox callback my ($ibx, $arg) = @_; my ($self, $eml, $loc) = @$arg; + eval { - my $im = _importer_for($self, $ibx); + # try to avoid taking a lock or unnecessary spawning + my $im = $self->{importers}->{"$ibx"}; + my $scrubbed; + if ((!$im || !$im->active) && $ibx->over) { + if (content_exists($ibx, $eml)) { + # continue + } elsif (my $scrub = $ibx->filter($im)) { + $scrubbed = $scrub->scrub($eml, 1); + if ($scrubbed && $scrubbed != REJECT && + !content_exists($ibx, $scrubbed)) { + return; + } + } else { + return; + } + } + + $im //= _importer_for($self, $ibx); # may spawn fast-import $im->remove($eml, 'spam'); - if (my $scrub = $ibx->filter($im)) { - my $scrubbed = $scrub->scrub($eml, 1); - if ($scrubbed && $scrubbed != REJECT) { - $im->remove($scrubbed, 'spam'); - } + $scrubbed //= do { + my $scrub = $ibx->filter($im); + $scrub ? $scrub->scrub($eml, 1) : undef; + }; + if ($scrubbed && $scrubbed != REJECT) { + $im->remove($scrubbed, 'spam'); } }; if ($@) {