]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
doc: re-add missing 1.6 release notes
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index 459c7e86eed189782c5b2c4517af5587fb7d8ee4..0104f87ae421e25960220c5a64d9c5d30c41f136 100644 (file)
@@ -17,6 +17,7 @@ use PublicInbox::InboxWritable;
 use PublicInbox::OverIdx;
 use PublicInbox::Msgmap;
 use PublicInbox::Spawn qw(spawn popen_rd run_die);
+use PublicInbox::Search;
 use PublicInbox::SearchIdx qw(log2stack is_ancestor check_size is_bad_blob);
 use IO::Handle; # ->autoflush
 use File::Temp ();
@@ -608,7 +609,11 @@ shard[$i] bad echo:$echo != $i waiting for txn commit
                }
 
                my $midx = $self->{midx}; # misc index
-               $midx->commit_txn if $midx;
+               if ($midx) {
+                       $midx->commit_txn;
+                       $PublicInbox::Search::X{CLOEXEC_UNSET} and
+                               $self->git->cleanup;
+               }
 
                # last_commit is special, don't commit these until
                # Xapian shards are done:
@@ -618,7 +623,10 @@ shard[$i] bad echo:$echo != $i waiting for txn commit
                        $dbh->commit;
                        $dbh->begin_work;
                }
-               $midx->begin_txn if $midx;
+               if ($midx) {
+                       $self->git->batch_prepare;
+                       $midx->begin_txn;
+               }
        }
        $self->{total_bytes} += $self->{transact_bytes};
        $self->{transact_bytes} = 0;
@@ -888,12 +896,16 @@ sub index_oid { # cat_async callback
        }
 
        # {unindexed} is unlikely
-       if ((my $unindexed = $arg->{unindexed}) && scalar(@$mids) == 1) {
-               $num = delete($unindexed->{$mids->[0]});
+       if (my $unindexed = $arg->{unindexed}) {
+               my $oidbin = pack('H*', $oid);
+               my $u = $unindexed->{$oidbin};
+               ($num, $mid0) = splice(@$u, 0, 2) if $u;
                if (defined $num) {
-                       $mid0 = $mids->[0];
                        $self->{mm}->mid_set($num, $mid0);
-                       delete($arg->{unindexed}) if !keys(%$unindexed);
+                       if (scalar(@$u) == 0) { # done with current OID
+                               delete $unindexed->{$oidbin};
+                               delete($arg->{unindexed}) if !keys(%$unindexed);
+                       }
                }
        }
        if (!defined($num)) { # reuse if reindexing (or duplicates)
@@ -1160,10 +1172,13 @@ sub unindex_oid ($$;$) { # git->cat_async callback
                        warn "BUG: multiple articles linked to $oid\n",
                                join(',',sort keys %gone), "\n";
                }
-               foreach my $num (keys %gone) {
+               # reuse (num => mid) mapping in ascending numeric order
+               for my $num (sort { $a <=> $b } keys %gone) {
+                       $num += 0;
                        if ($unindexed) {
                                my $mid0 = $mm->mid_for($num);
-                               $unindexed->{$mid0} = $num;
+                               my $oidbin = pack('H*', $oid);
+                               push @{$unindexed->{$oidbin}}, $num, $mid0;
                        }
                        $mm->num_delete($num);
                }
@@ -1179,7 +1194,7 @@ sub git { $_[0]->{ibx}->git }
 sub unindex_todo ($$$) {
        my ($self, $sync, $unit) = @_;
        my $unindex_range = delete($unit->{unindex_range}) // return;
-       my $unindexed = $sync->{unindexed} //= {}; # $mid0 => $num
+       my $unindexed = $sync->{unindexed} //= {}; # $oidbin => [$num, $mid0]
        my $before = scalar keys %$unindexed;
        # order does not matter, here:
        my $fh = $unit->{git}->popen(qw(log --raw -r --no-notes --no-color