about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/ExtSearchIdx.pm3
-rw-r--r--lib/PublicInbox/MiscIdx.pm19
-rw-r--r--lib/PublicInbox/V2Writable.pm4
3 files changed, 13 insertions, 13 deletions
diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index c782a62a..9b7340df 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -1003,8 +1003,7 @@ sub idx_init { # similar to V2Writable
         $self->with_umask(\&_idx_init, $self, $opt);
         $self->{oidx}->begin_lazy;
         $self->{oidx}->eidx_prep;
-        $self->git->batch_prepare;
-        $self->{midx}->begin_txn;
+        $self->{midx}->create_xdb if @new;
 }
 
 sub _watch_commit { # PublicInbox::DS::add_timer callback
diff --git a/lib/PublicInbox/MiscIdx.pm b/lib/PublicInbox/MiscIdx.pm
index ab5e029a..f5a374b2 100644
--- a/lib/PublicInbox/MiscIdx.pm
+++ b/lib/PublicInbox/MiscIdx.pm
@@ -39,25 +39,30 @@ sub new {
         }, $class;
 }
 
-sub begin_txn {
+sub _begin_txn ($) {
         my ($self) = @_;
-        croak 'BUG: already in txn' if $self->{xdb}; # XXX make lazy?
         my $wdb = $PublicInbox::Search::X{WritableDatabase};
         my $xdb = eval { $wdb->new($self->{mi_dir}, $self->{flags}) };
         croak "Failed opening $self->{mi_dir}: $@" if $@;
-        $self->{xdb} = $xdb;
         $xdb->begin_transaction;
+        $xdb;
 }
 
 sub commit_txn {
         my ($self) = @_;
-        croak 'BUG: not in txn' unless $self->{xdb}; # XXX make lazy?
-        delete($self->{xdb})->commit_transaction;
+        my $xdb = delete $self->{xdb} or return;
+        $xdb->commit_transaction;
+}
+
+sub create_xdb {
+        my ($self) = @_;
+        $self->{xdb} //= _begin_txn($self);
+        commit_txn($self);
 }
 
 sub remove_eidx_key {
         my ($self, $eidx_key) = @_;
-        my $xdb = $self->{xdb};
+        my $xdb = $self->{xdb} //= _begin_txn($self);
         my $head = $xdb->postlist_begin('Q'.$eidx_key);
         my $tail = $xdb->postlist_end('Q'.$eidx_key);
         my @docids; # only one, unless we had bugs
@@ -74,7 +79,7 @@ sub remove_eidx_key {
 sub index_ibx {
         my ($self, $ibx) = @_;
         my $eidx_key = $ibx->eidx_key;
-        my $xdb = $self->{xdb};
+        my $xdb = $self->{xdb} //= _begin_txn($self);
         # Q = uniQue in Xapian terminology
         my $head = $xdb->postlist_begin('Q'.$eidx_key);
         my $tail = $xdb->postlist_end('Q'.$eidx_key);
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 0104f87a..7f9342b0 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -623,10 +623,6 @@ shard[$i] bad echo:$echo != $i waiting for txn commit
                         $dbh->commit;
                         $dbh->begin_work;
                 }
-                if ($midx) {
-                        $self->git->batch_prepare;
-                        $midx->begin_txn;
-                }
         }
         $self->{total_bytes} += $self->{transact_bytes};
         $self->{transact_bytes} = 0;