From 1e63e0409004f1edb352f53729e2d4aed4825a22 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 17 Jul 2020 06:31:51 +0000 Subject: with_umask: pass args to callback While it makes the code flow slightly less well in some places, it saves us runtime allocations and indentation. --- lib/PublicInbox/Xapcmd.pm | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'lib/PublicInbox/Xapcmd.pm') 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 ($$) { -- cgit v1.2.3-24-ge0c7