]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
(ext)index: move {-regen_fmt} from $sync to $self
authorEric Wong <e@80x24.org>
Fri, 10 Jan 2025 23:18:10 +0000 (23:18 +0000)
committerEric Wong <e@80x24.org>
Tue, 14 Jan 2025 04:45:27 +0000 (04:45 +0000)
We rely on `local' anyways in some cases.  This is yet another
step towards eliminating the $sync structure.

lib/PublicInbox/ExtSearchIdx.pm
lib/PublicInbox/V2Writable.pm

index 25f2d8e72a19d0fdf9fff7ff3fdf2f394cc2152d..21f6b33a7a22498d53946a0aca0d01de2f716dd3 100644 (file)
@@ -794,7 +794,7 @@ sub eidxq_process ($$) { # for reindexing
        my $dbh = $self->{oidx}->dbh;
        my $tot = $dbh->selectrow_array('SELECT COUNT(*) FROM eidxq') or return;
        $self->{nrec} = 0;
-       local $sync->{-regen_fmt} = "%u/$tot\n";
+       local $self->{-regen_fmt} = "%u/$tot\n";
        my $pr = $self->{-opt}->{-progress};
        if ($pr) {
                my $min = $dbh->selectrow_array('SELECT MIN(docid) FROM eidxq');
@@ -899,7 +899,7 @@ sub _reindex_check_ibx ($$$) {
        # first, check if we missed any messages in target $ibx
        my $msgs;
        my $pr = $self->{-opt}->{-progress};
-       local $sync->{-regen_fmt} = "$ekey checking %u/$max\n";
+       local $self->{-regen_fmt} = "$ekey checking %u/$max\n";
        $self->{nrec} = 0;
        my $fast = $self->{-opt}->{fast};
        my $usr; # _unref_stale_range (< $lo) called
@@ -1047,7 +1047,7 @@ sub eidx_dedupe ($$$) {
        my ($max_id) = $self->{oidx}->dbh->selectrow_array(<<EOS);
 SELECT MAX(id) FROM msgid
 EOS
-       local $sync->{-regen_fmt} = "dedupe %u/$max_id\n";
+       local $self->{-regen_fmt} = "dedupe %u/$max_id\n";
 
        # note: we could write this query more intelligently,
        # but that causes lock contention with read-only processes
@@ -1118,12 +1118,12 @@ sub eidx_sync { # main entry point
        local $self->{need_checkpoint} = 0;
        local $self->{nrec} = 0;
        local $self->{-opt} = $opt;
+       local $self->{-regen_fmt} = "%u/?\n";
        my $sync = {
                # DO NOT SET {reindex} here, it's incompatible with reused
                # V2Writable code, reindex is totally different here
                # compared to v1/v2 inboxes because we have multiple histories
                self => $self,
-               -regen_fmt => "%u/?\n",
        };
        local $SIG{USR1} = sub { $self->{need_checkpoint} = 1 };
        my $quit = PublicInbox::SearchIdx::quit_cb($sync);
@@ -1298,9 +1298,9 @@ sub _watch_commit { # PublicInbox::DS::add_timer callback
        delete $self->{-commit_timer};
        eidxq_process($self, $self->{-watch_sync});
        eidxq_release($self);
-       my $fmt = delete $self->{-watch_sync}->{-regen_fmt};
+       my $fmt = delete $self->{-regen_fmt};
        reindex_checkpoint($self, $self->{-watch_sync});
-       $self->{-watch_sync}->{-regen_fmt} = $fmt;
+       $self->{-regen_fmt} = $fmt;
 
        # call event_step => done unless commit_timer is armed
        PublicInbox::DS::requeue($self);
index 74281fed4e00756c5e330825487ef482fe481707..ca231e0c53fae72a354ce253150cab1d5aaf27f2 100644 (file)
@@ -710,8 +710,8 @@ sub reindex_checkpoint ($$) {
                $self->done; # release lock
        }
 
-       if (my $pr = $sync->{-regen_fmt} ? $self->{-opt}->{-progress} : undef) {
-               $pr->(sprintf $sync->{-regen_fmt}, $self->{nrec});
+       if (my $pr = $self->{-regen_fmt} ? $self->{-opt}->{-progress} : undef) {
+               $pr->(sprintf $self->{-regen_fmt}, $self->{nrec});
        }
 
        # allow -watch or -mda to write...
@@ -986,14 +986,14 @@ sub sync_prepare ($$) {
        }
        return 0 if $sync->{quit};
        if (!$regen_max) {
-               $sync->{-regen_fmt} = "%u/?\n";
+               $self->{-regen_fmt} = "%u/?\n";
                return 0;
        }
 
        # reindex should NOT see new commits anymore, if we do,
        # it's a problem and we need to notice it via die()
        my $pad = length($regen_max) + 1;
-       $sync->{-regen_fmt} = "% ${pad}u/$regen_max\n";
+       $self->{-regen_fmt} = "% ${pad}u/$regen_max\n";
        $self->{nrec} = 0;
        return -1 if $sync->{reindex};
        $regen_max + $self->artnum_max || 0;
@@ -1176,10 +1176,8 @@ sub xapian_only ($;$$) {
        local $self->{parallel} = 0 if $seq;
        $self->idx_init($self->{-opt}); # acquire lock
        if (my $art_end = $self->{ibx}->mm->max) {
-               $sync //= {
-                       self => $self,
-                       -regen_fmt => "%u/?\n",
-               };
+               $self->{-regen_fmt} //= "%u/?\n";
+               $sync //= { self => $self };
                $sync->{art_end} = $art_end;
                if ($seq || !$self->{parallel}) {
                        my $shard_end = $self->{shards} - 1;
@@ -1206,6 +1204,7 @@ sub index_sync {
        local $self->{need_checkpoint} = 0;
        local $self->{nrec} = 0;
        local $self->{-opt} = $opt;
+       local $self->{-regen_fmt};
        return xapian_only($self) if $opt->{xapian_only};
 
        my $epoch_max = $self->{ibx}->max_git_epoch // return;
@@ -1263,7 +1262,7 @@ sub index_sync {
 
        if (my $nrec = $self->{nrec}) {
                my $pr = $self->{-opt}->{-progress};
-               $pr->('all.git '.sprintf($sync->{-regen_fmt}, $nrec)) if $pr;
+               $pr->('all.git '.sprintf($self->{-regen_fmt}, $nrec)) if $pr;
        }
 
        my $quit_warn;