From 88a9ef93229fc34e28105ae1736bd6e42ffc5e8c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 10 Jan 2025 23:20:07 +0000 Subject: [PATCH] (ext)index: eliminate redundant $sync->{epoch_max} We already had $self->{epoch_max}, and it's easy enough to `local'-ize it to ensure it doesn't outlive its usefulness when -extindex handles multiple inboxes. --- lib/PublicInbox/ExtSearchIdx.pm | 5 +++-- lib/PublicInbox/V2Writable.pm | 11 +++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index 0080c1db1..738028131 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -377,7 +377,7 @@ sub last_commits { my $heads = []; my $ekey = $self->{ibx}->eidx_key; my $uv = $self->{ibx}->uidvalidity; - for my $i (0..$sync->{epoch_max}) { + for my $i (0..$self->{epoch_max}) { $heads->[$i] = $self->{oidx}->eidx_meta("lc-v2:$ekey//$uv;$i"); } $heads; @@ -400,9 +400,10 @@ sub _sync_inbox ($$$) { $sync->{ibx} = $ibx; # FIXME: eliminate local $self->{ibx} = $ibx; $self->{nrec} = 0; + local $self->{epoch_max}; my $v = $ibx->version; if ($v == 2) { - $sync->{epoch_max} = $ibx->max_git_epoch // return; + $self->{epoch_max} = $ibx->max_git_epoch // return; sync_prepare($self, $sync); # or return # TODO: once MiscIdx is stable } elsif ($v == 1) { my $uv = $ibx->uidvalidity; diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 5fcc08006..e8d5e0052 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -838,7 +838,7 @@ sub update_last_commit { sub last_commits { my ($self, $sync) = @_; my $heads = []; - for (my $i = $sync->{epoch_max}; $i >= 0; $i--) { + for (my $i = $self->{epoch_max}; $i >= 0; $i--) { $heads->[$i] = last_epoch_commit($self, $i); } $heads; @@ -928,7 +928,7 @@ sub sync_prepare ($$) { $reindex_heads = []; my $v = PublicInbox::Search::SCHEMA_VERSION; my $mm = $self->{ibx}->mm; - for my $i (0..$sync->{epoch_max}) { + for my $i (0..$self->{epoch_max}) { $reindex_heads->[$i] = $mm->last_commit_xap($v, $i); } } elsif ($self->{reindex}) { # V2 inbox @@ -939,7 +939,7 @@ sub sync_prepare ($$) { $self->{max_size} = $self->{-opt}->{max_size} and $self->{index_oid} = $self->can('index_oid'); my $git_pfx = "$self->{ibx}->{inboxdir}/git"; - for (my $i = $sync->{epoch_max}; $i >= 0; $i--) { + for (my $i = $self->{epoch_max}; $i >= 0; $i--) { my $git_dir = "$git_pfx/$i.git"; -d $git_dir or next; # missing epochs are fine my $git = PublicInbox::Git->new($git_dir); @@ -1205,8 +1205,8 @@ sub index_sync { local $self->{-regen_fmt}; return xapian_only($self) if $opt->{xapian_only}; - my $epoch_max = $self->{ibx}->max_git_epoch // return; - my $latest = $self->{mg}->epoch_dir."/$epoch_max.git"; + local $self->{epoch_max} = $self->{ibx}->max_git_epoch // return; + my $latest = $self->{mg}->epoch_dir."/$self->{epoch_max}.git"; if ($opt->{'fast-noop'}) { # nanosecond (st_ctim) comparison use Time::HiRes qw(stat); if (my @mm = stat("$self->{ibx}->{inboxdir}/msgmap.sqlite3")) { @@ -1231,7 +1231,6 @@ sub index_sync { my $sync = { self => $self, ibx => $self->{ibx}, - epoch_max => $epoch_max, }; my $quit = PublicInbox::SearchIdx::quit_cb $self; local $SIG{QUIT} = $quit; -- 2.47.2