]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
SearchIdx: Decrement regen_down even for added messages that are later deleted.
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index aeb363e03d1d57a7ccd3cc7c1ae408cf98d91a05..0e0796c12c12373ebc211ef81446560870b4ba25 100644 (file)
@@ -561,7 +561,12 @@ sub read_log {
        while (defined($line = <$log>)) {
                if ($line =~ /$addmsg/o) {
                        my $blob = $1;
-                       delete $D{$blob} and next;
+                       if (delete $D{$blob}) {
+                               if (defined $self->{regen_down}) {
+                                       $self->{regen_down}--;
+                               }
+                               next;
+                       }
                        my $mime = do_cat_mail($git, $blob, \$bytes) or next;
                        batch_adjust(\$max, $bytes, $batch_cb, $latest);
                        $add_cb->($self, $mime, $bytes, $blob);
@@ -666,6 +671,7 @@ sub _index_sync {
 
                $self->{over}->rollback_lazy;
                $self->{over}->disconnect;
+               $git->cleanup;
                delete $self->{txn};
                $xdb->cancel_transaction;
                $xdb = _xdb_release($self);
@@ -696,6 +702,7 @@ sub _index_sync {
                        }
                }
                $self->commit_txn_lazy;
+               $git->cleanup;
                $xdb = _xdb_release($self);
                # let another process do some work... <
                if (!$newest) {
@@ -752,18 +759,23 @@ sub remote_remove {
 sub begin_txn_lazy {
        my ($self) = @_;
        return if $self->{txn};
-       my $xdb = $self->{xdb} || $self->_xdb_acquire;
-       $self->{over}->begin_lazy if $self->{over};
-       $xdb->begin_transaction;
-       $self->{txn} = 1;
-       $xdb;
+
+       $self->{-inbox}->with_umask(sub {
+               my $xdb = $self->{xdb} || $self->_xdb_acquire;
+               $self->{over}->begin_lazy if $self->{over};
+               $xdb->begin_transaction;
+               $self->{txn} = 1;
+               $xdb;
+       });
 }
 
 sub commit_txn_lazy {
        my ($self) = @_;
        delete $self->{txn} or return;
-       $self->{xdb}->commit_transaction;
-       $self->{over}->commit_lazy if $self->{over};
+       $self->{-inbox}->with_umask(sub {
+               $self->{xdb}->commit_transaction;
+               $self->{over}->commit_lazy if $self->{over};
+       });
 }
 
 sub worker_done {