about summary refs log tree commit homepage
path: root/lib/PublicInbox/V2Writable.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/V2Writable.pm')
-rw-r--r--lib/PublicInbox/V2Writable.pm16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index aa812a6b..f575ba11 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -133,12 +133,17 @@ sub add {
         $self->{ibx}->with_umask(\&_add, $self, $eml, $check_cb);
 }
 
+sub idx_shard ($$) {
+        my ($self, $num) = @_;
+        $self->{idx_shards}->[$num % scalar(@{$self->{idx_shards}})];
+}
+
 # indexes a message, returns true if checkpointing is needed
 sub do_idx ($$$$) {
         my ($self, $msgref, $mime, $smsg) = @_;
         $smsg->{bytes} = $smsg->{raw_bytes} + crlf_adjust($$msgref);
         $self->{oidx}->add_overview($mime, $smsg);
-        my $idx = idx_shard($self, $smsg->{num} % $self->{shards});
+        my $idx = idx_shard($self, $smsg->{num});
         $idx->index_raw($msgref, $mime, $smsg);
         my $n = $self->{transact_bytes} += $smsg->{raw_bytes};
         $n >= $self->{batch_bytes};
@@ -249,11 +254,6 @@ sub v2_num_for_harder {
         ($num, $mid0);
 }
 
-sub idx_shard {
-        my ($self, $shard_i) = @_;
-        $self->{idx_shards}->[$shard_i];
-}
-
 sub _idx_init { # with_umask callback
         my ($self, $opt) = @_;
         $self->lock_acquire unless $opt && $opt->{-skip_lock};
@@ -1102,7 +1102,7 @@ sub unindex_oid_remote ($$$) {
         my ($self, $oid, $mid) = @_;
         my @removed = $self->{oidx}->remove_oid($oid, $mid);
         for my $num (@removed) {
-                my $idx = idx_shard($self, $num % $self->{shards});
+                my $idx = idx_shard($self, $num);
                 $idx->shard_remove($oid, $num);
         }
 }
@@ -1183,7 +1183,7 @@ sub sync_ranges ($$$) {
 sub index_xap_only { # git->cat_async callback
         my ($bref, $oid, $type, $size, $smsg) = @_;
         my $self = $smsg->{v2w};
-        my $idx = idx_shard($self, $smsg->{num} % $self->{shards});
+        my $idx = idx_shard($self, $smsg->{num});
         $smsg->{raw_bytes} = $size;
         $idx->index_raw($bref, undef, $smsg);
         $self->{transact_bytes} += $size;