From: Eric Wong <e@yhbt.net>
Date: Sun, 2 Feb 2020 06:52:16 +0000 (+0000)
Subject: v2writable: do not clobber {shards} or {parallel} if unset
X-Git-Tag: v1.3.0~29
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=45e2c97624268da5e030ac3e4c033e6022b8c0de;p=public-inbox.git

v2writable: do not clobber {shards} or {parallel} if unset

The $jobs parameter in `public-inbox-convert' is passed to
V2Writable->init_inbox as `undef' by default, causing
parallelization to be disabled.

Instead, leave the underlying {parallel} flag untouched if
$shards is undef and do not clobber the default shard count.

This allows us to take advantage of multicore systems when
running public-inbox-convert with no command-line switches.
---

diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 37d27302..72d8d5af 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -107,8 +107,11 @@ sub new {
 
 # public (for now?)
 sub init_inbox {
-	my ($self, $parallel, $skip_epoch) = @_;
-	$self->{parallel} = $parallel;
+	my ($self, $shards, $skip_epoch) = @_;
+	if (defined $shards) {
+		$self->{parallel} = 0 if $shards == 0;
+		$self->{shards} = $shards if $shards > 0;
+	}
 	$self->idx_init;
 	my $epoch_max = -1;
 	git_dir_latest($self, \$epoch_max);