We don't want to monopolize locks because processes can easily
block each other if using `watchspam' on a Maildir while a big
NNTP or IMAP import is happening.
This can also happen if somebody configured a single inbox to
watch from several sources to merge several mailboxes into one
(e.g. both an IMAP and Maildir are watched).
return unless $mdre || scalar(keys %imap) || scalar(keys %nntp);
bless {
return unless $mdre || scalar(keys %imap) || scalar(keys %nntp);
bless {
+ max_batch => 10, # avoid hogging locks for too long
spamcheck => $spamcheck,
mdmap => \%mdmap,
mdre => $mdre,
spamcheck => $spamcheck,
mdmap => \%mdmap,
mdre => $mdre,
$l_uid = $uids->[-1] + 1; # for next search
my $last_uid;
$l_uid = $uids->[-1] + 1; # for next search
my $last_uid;
+ my $n = $self->{max_batch};
+ if (--$n < 0) {
+ _done_for_now($self);
+ $itrk->update_last($r_uidval, $last_uid);
+ $n = $self->{max_batch};
+ }
my @batch = splice(@$uids, 0, $bs);
$batch = join(',', @batch);
local $0 = "UID:$batch $mbx $sec";
my @batch = splice(@$uids, 0, $bs);
$batch = join(',', @batch);
local $0 = "UID:$batch $mbx $sec";
};
my $inboxes = $self->{nntp}->{$url};
my $last_art;
};
my $inboxes = $self->{nntp}->{$url};
my $last_art;
+ my $n = $self->{max_batch};
for ($beg..$end) {
last if $self->{quit};
$art = $_;
for ($beg..$end) {
last if $self->{quit};
$art = $_;
+ if (--$n < 0) {
+ _done_for_now($self);
+ $itrk->update_last(0, $last_art);
+ $n = $self->{max_batch};
+ }
my $raw = $nn->article($art);
unless (defined($raw)) {
my $msg = $nn->message;
my $raw = $nn->article($art);
unless (defined($raw)) {
my $msg = $nn->message;
local $PublicInbox::DS::in_loop = 0; # waitpid() synchronously
# continue existing scan
local $PublicInbox::DS::in_loop = 0; # waitpid() synchronously
# continue existing scan
my $opendirs = $self->{opendirs};
my @dirnames = keys %$opendirs;
foreach my $dir (@dirnames) {
my $dh = delete $opendirs->{$dir};
my $opendirs = $self->{opendirs};
my @dirnames = keys %$opendirs;
foreach my $dir (@dirnames) {
my $dh = delete $opendirs->{$dir};
+ my $n = $self->{max_batch};
while (my $fn = readdir($dh)) {
_try_path($self, "$dir/$fn");
last if --$n < 0;
while (my $fn = readdir($dh)) {
_try_path($self, "$dir/$fn");
last if --$n < 0;
warn "failed to open $dir: $!\n";
next;
}
warn "failed to open $dir: $!\n";
next;
}
+ my $n = $self->{max_batch};
while (my $fn = readdir($dh)) {
_try_path($self, "$dir/$fn");
last if --$n < 0;
while (my $fn = readdir($dh)) {
_try_path($self, "$dir/$fn");
last if --$n < 0;