lib/PublicInbox/V2Writable.pm | 29 ++++++++++++++++------------- diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index a403f22feb2220eaca68b3ea6b58016a7e6b9e0b..7c7be1bd100c9cc613a9eb6a7229aa438b1f8354 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -964,9 +964,9 @@ last_epoch_commit($self, $i, $cmt); } sub last_commits ($$) { - my ($self, $epoch_max) = @_; + my ($self, $sync) = @_; my $heads = []; - for (my $i = $epoch_max; $i >= 0; $i--) { + for (my $i = $sync->{epoch_max}; $i >= 0; $i--) { $heads->[$i] = last_epoch_commit($self, $i); } $heads; @@ -1023,17 +1023,20 @@ } $range; } -sub sync_prepare ($$$) { - my ($self, $sync, $epoch_max) = @_; +# overridden by ExtSearchIdx +sub artnum_max { $_[0]->{mm}->num_highwater } + +sub sync_prepare ($$) { + my ($self, $sync) = @_; my $pr = $sync->{-opt}->{-progress}; my $regen_max = 0; my $head = $sync->{ibx}->{ref_head} || 'HEAD'; # reindex stops at the current heads and we later rerun index_sync # without {reindex} - my $reindex_heads = $self->last_commits($epoch_max) if $sync->{reindex}; + my $reindex_heads = $self->last_commits($sync) if $sync->{reindex}; - for (my $i = $epoch_max; $i >= 0; $i--) { + for (my $i = $sync->{epoch_max}; $i >= 0; $i--) { my $git_dir = $sync->{ibx}->git_dir_n($i); -d $git_dir or next; # missing epochs are fine my $git = PublicInbox::Git->new($git_dir); @@ -1081,7 +1084,7 @@ my $pad = length($regen_max) + 1; $sync->{-regen_fmt} = "% ${pad}u/$regen_max\n"; $sync->{nr} = \(my $nr = 0); return -1 if $sync->{reindex}; - $regen_max + $self->{mm}->num_highwater() || 0; + $regen_max + $self->artnum_max || 0; } sub unindex_oid_aux ($$$) { @@ -1152,11 +1155,10 @@ PublicInbox::Import::run_die(['git', "--git-dir=$git->{git_dir}", qw(-c gc.reflogExpire=now gc --prune=all --quiet)]); } -sub sync_ranges ($$$) { - my ($self, $sync, $epoch_max) = @_; +sub sync_ranges ($$) { + my ($self, $sync) = @_; my $reindex = $sync->{reindex}; - - return last_commits($self, $epoch_max) unless $reindex; + return $self->last_commits($sync) unless $reindex; return [] if ref($reindex) ne 'HASH'; my $ranges = $reindex->{from}; # arrayref; @@ -1286,9 +1288,10 @@ reindex => $opt->{reindex}, -opt => $opt, v2w => $self, ibx => $self->{ibx}, + epoch_max => $epoch_max, }; - $sync->{ranges} = sync_ranges($self, $sync, $epoch_max); - if (sync_prepare($self, $sync, $epoch_max)) { + $sync->{ranges} = sync_ranges($self, $sync); + if (sync_prepare($self, $sync)) { # tmp_clone seems to fail if inside a transaction, so # we rollback here (because we opened {mm} for reading) # Note: we do NOT rely on DBI transactions for atomicity;