about summary refs log tree commit homepage
path: root/lib/PublicInbox/TestCommon.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-15 12:58:04 +0100
committerEric Wong <e@80x24.org>2021-03-15 16:54:30 -0400
commita82c3ceb838e8bb478440263790c28ebae6ec9cd (patch)
treec49cf4bf396bd9b2231e800d8bc960839f041649 /lib/PublicInbox/TestCommon.pm
parent8954ae12611d407346a9b67e822309a7e48b943e (diff)
downloadpublic-inbox-a82c3ceb838e8bb478440263790c28ebae6ec9cd.tar.gz
Suprisingly, this saves over 100 milliseconds.
Diffstat (limited to 'lib/PublicInbox/TestCommon.pm')
-rw-r--r--lib/PublicInbox/TestCommon.pm7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 6ca69174..c2d07e59 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -593,13 +593,17 @@ sub create_inbox ($$;@) {
         require PublicInbox::InboxWritable;
         my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
         my $dir = "t/data-gen/$base.$ident";
-        unless (-d $dir) {
+        my $new = !-d $dir;
+        if ($new) {
                 mkdir $dir; # may race
                 -d $dir or BAIL_OUT "$dir could not be created: $!";
         }
         my $lk = bless { lock_path => "$dir/creat.lock" }, 'PublicInbox::Lock';
         $opt{inboxdir} = File::Spec->rel2abs($dir);
         $opt{name} //= $ident;
+        my $scope = $lk->lock_for_scope;
+        my $pre_cb = delete $opt{pre_cb};
+        $pre_cb->($dir) if $pre_cb && $new;
         $opt{-no_fsync} = 1;
         my $no_gc = delete $opt{-no_gc};
         my $tmpdir = delete $opt{tmpdir};
@@ -608,7 +612,6 @@ sub create_inbox ($$;@) {
         my $parallel = delete($opt{importer_parallel}) // 0;
         my $creat_opt = { nproc => delete($opt{nproc}) // 1 };
         my $ibx = PublicInbox::InboxWritable->new({ %opt }, $creat_opt);
-        my $scope = $lk->lock_for_scope;
         if (!-f "$dir/creat.stamp") {
                 my $im = $ibx->importer($parallel);
                 $cb->($im, $ibx);