diff options
author | Eric Wong <e@yhbt.net> | 2020-07-17 06:31:51 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-07-17 20:56:51 +0000 |
commit | 1e63e0409004f1edb352f53729e2d4aed4825a22 (patch) | |
tree | 1c3db8856122e13122be01e15538220f6f04f18d /lib/PublicInbox/Xapcmd.pm | |
parent | c6d0a81e6ca7a5da9f9ff193f0992705aa9f9682 (diff) | |
download | public-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/Xapcmd.pm')
-rw-r--r-- | lib/PublicInbox/Xapcmd.pm | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index a57fa559..c04f935c 100644 --- a/lib/PublicInbox/Xapcmd.pm +++ b/lib/PublicInbox/Xapcmd.pm @@ -229,6 +229,24 @@ sub prepare_run { sub check_compact () { runnable_or_die($XAPIAN_COMPACT) } +sub _run { + my ($ibx, $cb, $opt, $reindex) = @_; + my $im = $ibx->importer(0); + $im->lock_acquire; + my ($tmp, $queue) = prepare_run($ibx, $opt); + + # fine-grained locking if we prepare for reindex + if (!$opt->{-coarse_lock}) { + prepare_reindex($ibx, $im, $reindex); + $im->lock_release; + } + + $ibx->cleanup; + process_queue($queue, $cb, $opt); + $im->lock_acquire if !$opt->{-coarse_lock}; + commit_changes($ibx, $im, $tmp, $opt); +} + sub run { my ($ibx, $task, $opt) = @_; # task = 'cpdb' or 'compact' my $cb = \&${\"PublicInbox::Xapcmd::$task"}; @@ -248,22 +266,7 @@ sub run { local %SIG = %SIG; setup_signals(); $ibx->umask_prepare; - $ibx->with_umask(sub { - my $im = $ibx->importer(0); - $im->lock_acquire; - my ($tmp, $queue) = prepare_run($ibx, $opt); - - # fine-grained locking if we prepare for reindex - if (!$opt->{-coarse_lock}) { - prepare_reindex($ibx, $im, $reindex); - $im->lock_release; - } - - $ibx->cleanup; - process_queue($queue, $cb, $opt); - $im->lock_acquire if !$opt->{-coarse_lock}; - commit_changes($ibx, $im, $tmp, $opt); - }); + $ibx->with_umask(\&_run, $ibx, $cb, $opt, $reindex); } sub cpdb_retryable ($$) { |