]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
v2writable: detect shard count for ExtSearchIdx properly
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index a3938b5628f854ea1508b7063623c312dcf2a4f1..e9a4300072846d70e1376fe978405b508c55dbc9 100644 (file)
@@ -65,13 +65,21 @@ sub nproc_shards ($) {
 
 sub count_shards ($) {
        my ($self) = @_;
-       $self->{ibx} ? do {
+       if (my $ibx = $self->{ibx}) {
                # always load existing shards in case core count changes:
                # Also, shard count may change while -watch is running
-               my $srch = $self->{ibx}->search or return 0;
-               delete $self->{ibx}->{search};
+               my $srch = $ibx->search or return 0;
+               delete $ibx->{search};
                $srch->{nshard} // 0
-       } : $self->{nshard}; # self->{nshard} is for ExtSearchIdx
+       } else { # ExtSearchIdx
+               $self->{nshard} // do {
+                       if ($self->xdb_sharded) {
+                               $self->{nshard} // die 'BUG: {nshard} unset';
+                       } else {
+                               0;
+                       }
+               }
+       }
 }
 
 sub new {