]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
(ext)index: eliminate redundant $sync->{epoch_max}
authorEric Wong <e@80x24.org>
Fri, 10 Jan 2025 23:20:07 +0000 (23:20 +0000)
committerEric Wong <e@80x24.org>
Tue, 14 Jan 2025 04:45:41 +0000 (04:45 +0000)
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
lib/PublicInbox/V2Writable.pm

index 0080c1db1e5db1508d2e796d80dee4697fbe2f88..738028131cefef28dd9f48c938ea19557f19b8ed 100644 (file)
@@ -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;
index 5fcc0800639623b55af3fc4e92f99f92c4b7b0b8..e8d5e0052030b474c36a6a7a70e401ba660e159a 100644 (file)
@@ -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;