about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchIdx.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-07-17 06:31:51 +0000
committerEric Wong <e@yhbt.net>2020-07-17 20:56:51 +0000
commit1e63e0409004f1edb352f53729e2d4aed4825a22 (patch)
tree1c3db8856122e13122be01e15538220f6f04f18d /lib/PublicInbox/SearchIdx.pm
parentc6d0a81e6ca7a5da9f9ff193f0992705aa9f9682 (diff)
downloadpublic-inbox-1e63e0409004f1edb352f53729e2d4aed4825a22.tar.gz
While it makes the code flow slightly less well in some places,
it saves us runtime allocations and indentation.
Diffstat (limited to 'lib/PublicInbox/SearchIdx.pm')
-rw-r--r--lib/PublicInbox/SearchIdx.pm40
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 4caa66d3..c93c9034 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -585,7 +585,7 @@ sub unindex_both { # git->cat_async callback
 sub index_sync {
         my ($self, $opts) = @_;
         delete $self->{lock_path} if $opts->{-skip_lock};
-        $self->{-inbox}->with_umask(sub { $self->_index_sync($opts) })
+        $self->{-inbox}->with_umask(\&_index_sync, $self, $opts);
 }
 
 sub too_big ($$$) {
@@ -854,17 +854,18 @@ sub remote_remove {
         }
 }
 
-sub begin_txn_lazy {
+sub _begin_txn {
         my ($self) = @_;
-        return if $self->{txn};
+        my $xdb = $self->{xdb} || $self->_xdb_acquire;
+        $self->{over}->begin_lazy if $self->{over};
+        $xdb->begin_transaction if $xdb;
+        $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 if $xdb;
-                $self->{txn} = 1;
-                $xdb;
-        });
+sub begin_txn_lazy {
+        my ($self) = @_;
+        $self->{-inbox}->with_umask(\&_begin_txn, $self) if !$self->{txn};
 }
 
 # store 'indexlevel=medium' in v2 shard=0 and v1 (only one shard)
@@ -882,16 +883,19 @@ sub set_indexlevel {
         }
 }
 
+sub _commit_txn {
+        my ($self) = @_;
+        if (my $xdb = $self->{xdb}) {
+                set_indexlevel($self);
+                $xdb->commit_transaction;
+        }
+        $self->{over}->commit_lazy if $self->{over};
+}
+
 sub commit_txn_lazy {
         my ($self) = @_;
-        delete $self->{txn} or return;
-        $self->{-inbox}->with_umask(sub {
-                if (my $xdb = $self->{xdb}) {
-                        set_indexlevel($self);
-                        $xdb->commit_transaction;
-                }
-                $self->{over}->commit_lazy if $self->{over};
-        });
+        delete($self->{txn}) and
+                $self->{-inbox}->with_umask(\&_commit_txn, $self);
 }
 
 sub worker_done {