]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
index: move {reindex} to $self
authorEric Wong <e@80x24.org>
Fri, 10 Jan 2025 23:19:00 +0000 (23:19 +0000)
committerEric Wong <e@80x24.org>
Tue, 14 Jan 2025 04:45:35 +0000 (04:45 +0000)
Again, we can easily contain the scope of {reindex} to $self via
`local', so there's no need to rely on another temporary structure.

lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/V2Writable.pm

index 0e84a6a660bf04a56e97ae693eaab5d90f5d2384..a9e4df6236cededf6053e354e5812b8fdc3830a7 100644 (file)
@@ -529,7 +529,7 @@ sub v1_index_mm ($$$$) {
        my ($self, $eml, $oid, $sync) = @_;
        my $mids = mids($eml);
        my $mm = $self->{mm};
-       if ($sync->{reindex}) {
+       if ($self->{reindex}) {
                my $oidx = $self->{oidx};
                for my $mid (@$mids) {
                        my ($num, undef) = $oidx->num_mid0_for_oid($oid, $mid);
@@ -883,7 +883,7 @@ sub v1_checkpoint ($$;$) {
        if ($stk) { # all done if $stk is passed
                # let SearchView know a full --reindex was done so it can
                # generate ->has_threadid-dependent links
-               if ($xdb && $sync->{reindex} && !ref($sync->{reindex})) {
+               if ($xdb && $self->{reindex} && !ref($self->{reindex})) {
                        my $n = $xdb->get_metadata('has_threadid');
                        $xdb->set_metadata('has_threadid', '1') if $n ne '1';
                }
@@ -1006,7 +1006,7 @@ sub prepare_stack ($$$) {
                $git->qx(qw(rev-parse -q --verify), "$range^0");
                return PublicInbox::IdxStack->new->read_prepare if $?;
        }
-       local $self->{D} = $sync->{reindex} ? {} : undef; # OID_BIN => NR
+       local $self->{D} = $self->{reindex} ? {} : undef; # OID_BIN => NR
        log2stack($self, $sync, $git, $range);
 }
 
@@ -1084,7 +1084,8 @@ sub _index_sync {
        local $self->{transact_bytes} = 0;
        my $pr = $opt->{-progress};
        local $self->{-opt} = $opt;
-       my $sync = { reindex => $opt->{reindex}, ibx => $ibx };
+       local $self->{reindex} = $opt->{reindex};
+       my $sync = { ibx => $ibx };
        my $quit = quit_cb $self;
        local $SIG{QUIT} = $quit;
        local $SIG{INT} = $quit;
@@ -1092,18 +1093,18 @@ sub _index_sync {
        my $xdb = $self->begin_txn_lazy;
        $self->{oidx}->rethread_prepare($opt);
        my $mm = v1_mm_init $self;
-       if ($sync->{reindex}) {
+       if ($self->{reindex}) {
                my $last = $mm->last_commit;
                if ($last) {
                        $tip = $last;
                } else {
                        # somebody just blindly added --reindex when indexing
                        # for the first time, allow it:
-                       undef $sync->{reindex};
+                       delete $self->{reindex};
                }
        }
        my $last_commit = v1_last_x_commit $self, $mm;
-       my $lx = v1_reindex_from $sync->{reindex}, $last_commit;
+       my $lx = v1_reindex_from $self->{reindex}, $last_commit;
        my $range = $lx eq '' ? $tip : "$lx..$tip";
        $pr->("counting changes\n\t$range ... ") if $pr;
        my $stk = prepare_stack($self, $sync, $range);
index 6ab9cbaf4a4d22de4901efeab1190772f8b14f2d..31d8dcdae3a665e41cc7ceb3e2cfb6898daa3f04 100644 (file)
@@ -931,7 +931,7 @@ sub sync_prepare ($$) {
                for my $i (0..$sync->{epoch_max}) {
                        $reindex_heads->[$i] = $mm->last_commit_xap($v, $i);
                }
-       } elsif ($sync->{reindex}) { # V2 inbox
+       } elsif ($self->{reindex}) { # V2 inbox
                # reindex stops at the current heads and we later
                # rerun index_sync without {reindex}
                $reindex_heads = $self->last_commits($sync);
@@ -959,7 +959,7 @@ sub sync_prepare ($$) {
                # We intentionally do NOT use {D} in the non-reindex case
                # because we want NNTP article number gaps from unindexed
                # messages to show up in mirrors, too.
-               $self->{D} //= $sync->{reindex} ? {} : undef; # OID_BIN => NR
+               $self->{D} //= $self->{reindex} ? {} : undef; # OID_BIN => NR
                my $stk = log2stack($self, $sync, $git, $range);
                return 0 if $self->{quit};
                my $nr = $stk ? $stk->num_records : 0;
@@ -995,7 +995,7 @@ sub sync_prepare ($$) {
        my $pad = length($regen_max) + 1;
        $self->{-regen_fmt} = "% ${pad}u/$regen_max\n";
        $self->{nrec} = 0;
-       return -1 if $sync->{reindex};
+       return -1 if $self->{reindex};
        $regen_max + $self->artnum_max || 0;
 }
 
@@ -1077,7 +1077,7 @@ sub unindex_todo ($$$) {
 
 sub sync_ranges ($$) {
        my ($self, $sync) = @_;
-       my $reindex = $sync->{reindex};
+       my $reindex = $self->{reindex};
        return $self->last_commits($sync) unless $reindex;
        return [] if ref($reindex) ne 'HASH';
 
@@ -1227,8 +1227,8 @@ sub index_sync {
        $self->idx_init($opt); # acquire lock
        $self->{mg}->fill_alternates;
        $self->{oidx}->rethread_prepare($opt);
+       local $self->{reindex} = $opt->{reindex};
        my $sync = {
-               reindex => $opt->{reindex},
                self => $self,
                ibx => $self->{ibx},
                epoch_max => $epoch_max,