]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
(ext)index: ${$sync->{nr}} to $self->{nrec}
authorEric Wong <e@80x24.org>
Fri, 10 Jan 2025 23:18:08 +0000 (23:18 +0000)
committerEric Wong <e@80x24.org>
Tue, 14 Jan 2025 04:45:25 +0000 (04:45 +0000)
{nrec} is probably less confusing as a name in a long-lived
context and we can get rid of the awkward scalar dereferencing
by using $self.

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

index 970d5eb3170ff32873a0a39c81a1c7693bb66056..ebbb2af13c4b624dccb3f8ccc507ebc2f89c09b6 100644 (file)
@@ -349,7 +349,7 @@ sub index_oid { # git->cat_async callback for 'm'
                blob => $oid,
        }, 'PublicInbox::Smsg';
        $new_smsg->set_bytes($$bref, $size);
-       ++${$req->{nr}};
+       ++$self->{nrec};
        my $mismatch = [];
        $req->{xnum} = cur_ibx_xnum($req, $bref, $mismatch) // do {
                warn "# deleted\n";
@@ -397,7 +397,7 @@ sub _sync_inbox ($$$) {
                return "W: skipping $ekey ($err)";
        }
        $sync->{ibx} = $ibx;
-       $sync->{nr} = \(my $nr = 0);
+       $self->{nrec} = 0;
        my $v = $ibx->version;
        if ($v == 2) {
                $sync->{epoch_max} = $ibx->max_git_epoch // return;
@@ -528,10 +528,8 @@ sub eidx_gc { # top-level entry point
        $opt->{-idx_gc} = 1;
        local $self->{checkpoint_unlocks} = 1;
        local $self->{need_checkpoint} = 0;
-       my $sync = {
-               -opt => $opt,
-               self => $self,
-       };
+       local $self->{nrec};
+       my $sync = { -opt => $opt, self => $self };
        $self->idx_init($opt); # acquire lock via V2Writable::_idx_init
        eidx_gc_scan_inboxes($self, $sync);
        eidx_gc_scan_shards($self, $sync);
@@ -793,7 +791,7 @@ sub eidxq_process ($$) { # for reindexing
        return unless ($self->{cfg} && eidxq_lock_acquire($self));
        my $dbh = $self->{oidx}->dbh;
        my $tot = $dbh->selectrow_array('SELECT COUNT(*) FROM eidxq') or return;
-       ${$sync->{nr}} = 0;
+       $self->{nrec} = 0;
        local $sync->{-regen_fmt} = "%u/$tot\n";
        my $pr = $sync->{-opt}->{-progress};
        if ($pr) {
@@ -815,7 +813,7 @@ restart:
                        warn "E: #$docid does not exist in over\n";
                }
                $del->execute($docid);
-               ++${$sync->{nr}};
+               ++$self->{nrec};
 
                if (update_checkpoint $self) {
                        $dbh = $del = $iter = undef;
@@ -825,7 +823,7 @@ restart:
                }
        }
        $self->git->async_wait_all;
-       $pr->("reindexed ${$sync->{nr}}/$tot\n") if $pr;
+       $pr->("reindexed $self->{nrec}/$tot\n") if $pr;
 }
 
 sub _reindex_unseen { # git->cat_async callback
@@ -900,12 +898,12 @@ sub _reindex_check_ibx ($$$) {
        my $msgs;
        my $pr = $sync->{-opt}->{-progress};
        local $sync->{-regen_fmt} = "$ekey checking %u/$max\n";
-       ${$sync->{nr}} = 0;
+       $self->{nrec} = 0;
        my $fast = $sync->{-opt}->{fast};
        my $usr; # _unref_stale_range (< $lo) called
        my ($lo, $hi);
        while (scalar(@{$msgs = $ibx->over->query_xover($beg, $end, $opt)})) {
-               ${$sync->{nr}} = $beg;
+               $self->{nrec} = $beg;
                $beg = $msgs->[-1]->{num} + 1;
                $end = $beg + $slice;
                $end = $max if $end > $max;
@@ -1067,7 +1065,7 @@ EOS
        while (my ($mid, $id) = $iter->fetchrow_array) {
                last if $sync->{quit};
                $self->{current_info} = "dedupe $mid";
-               ${$sync->{nr}} = $min_id = $id;
+               $self->{nrec} = $min_id = $id;
                my ($prv, @smsg);
                while (my $x = $self->{oidx}->next_by_mid($mid, \$id, \$prv)) {
                        push @smsg, $x;
@@ -1105,7 +1103,7 @@ EOS
        if (my $pr = $sync->{-opt}->{-progress}) {
                $pr->("culled $n/$candidates candidates ($nr_mid msgids)\n");
        }
-       ${$sync->{nr}} = 0;
+       $self->{nrec} = 0;
 }
 
 sub eidx_sync { # main entry point
@@ -1116,6 +1114,7 @@ sub eidx_sync { # main entry point
        $self->idx_init($opt); # acquire lock via V2Writable::_idx_init
        $self->{oidx}->rethread_prepare($opt);
        local $self->{need_checkpoint} = 0;
+       local $self->{nrec} = 0;
        my $sync = {
                -opt => $opt,
                # DO NOT SET {reindex} here, it's incompatible with reused
index 8ac8cac312a46ae01f23e590c29828f1defbad7f..34df5c90cd8d61f286644ef8dceb6649cd816e2e 100644 (file)
@@ -801,7 +801,6 @@ sub update_checkpoint ($;$) {
 sub index_both { # git->cat_async callback
        my ($bref, $oid, $type, $size, $sync) = @_;
        return if is_bad_blob($oid, $type, $size, $sync->{oid});
-       ++${$sync->{nr}};
        my $smsg = bless { blob => $oid }, 'PublicInbox::Smsg';
        $smsg->set_bytes($$bref, $size);
        my $self = $sync->{sidx};
@@ -812,6 +811,7 @@ sub index_both { # git->cat_async callback
                die "E: could not generate NNTP article number for $oid";
        add_message($self, $eml, $smsg, $sync);
        ++$self->{nidx};
+       ++$self->{nrec};
        my $cur_cmt = $sync->{cur_cmt} // die 'BUG: {cur_cmt} missing';
        ${$sync->{latest_cmt}} = $cur_cmt;
 }
@@ -891,11 +891,11 @@ sub v1_checkpoint ($$;$) {
        }
        commit_txn_lazy($self);
        $sync->{ibx}->git->cleanup;
-       my $nr = ${$sync->{nr}};
-       idx_release($self, $nr);
+       my $nrec = $self->{nrec};
+       idx_release($self, $nrec);
        # let another process do some work...
        if (my $pr = $sync->{-opt}->{-progress}) {
-               $pr->("indexed $nr/$sync->{ntodo}\n") if $nr;
+               $pr->("indexed $nrec/$sync->{ntodo}\n") if $nrec;
        }
        if (!$stk && !$sync->{quit}) { # more to come
                begin_txn_lazy($self);
@@ -909,8 +909,7 @@ sub v1_checkpoint ($$;$) {
 sub process_stack {
        my ($self, $sync, $stk) = @_;
        my $git = $sync->{ibx}->git;
-       my $nr = 0;
-       $sync->{nr} = \$nr;
+       $self->{nrec} = 0;
        $sync->{sidx} = $self;
        local $self->{need_checkpoint} = 0;
        $sync->{latest_cmt} = \(my $latest_cmt);
index 61c41b6053a477d6b00b1592359d45eeaa9ef52c..dd3258f3932867b431b661bc9eafee2eaa218ecd 100644 (file)
@@ -711,7 +711,7 @@ sub reindex_checkpoint ($$) {
        }
 
        if (my $pr = $sync->{-regen_fmt} ? $sync->{-opt}->{-progress} : undef) {
-               $pr->(sprintf($sync->{-regen_fmt}, ${$sync->{nr}}));
+               $pr->(sprintf $sync->{-regen_fmt}, $self->{nrec});
        }
 
        # allow -watch or -mda to write...
@@ -803,7 +803,7 @@ sub index_oid { # cat_async callback
                warn "E: $oid <", join('> <', @$mids), "> is a duplicate\n";
                return;
        }
-       ++${$arg->{nr}};
+       ++$self->{nrec};
        my $smsg = bless {
                num => $num,
                blob => $oid,
@@ -994,7 +994,7 @@ sub sync_prepare ($$) {
        # 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";
-       $sync->{nr} = \(my $nr = 0);
+       $self->{nrec} = 0;
        return -1 if $sync->{reindex};
        $regen_max + $self->artnum_max || 0;
 }
@@ -1115,7 +1115,7 @@ sub index_xap_step ($$$;$) {
                # have timeout problems like SQLite
                my $n = $self->{transact_bytes} += $smsg->{bytes};
                if ($n >= $self->{batch_bytes}) {
-                       ${$sync->{nr}} = $num;
+                       $self->{nrec} = $num;
                        reindex_checkpoint($self, $sync);
                }
        }
@@ -1179,7 +1179,6 @@ sub xapian_only {
                $sync //= {
                        -opt => $opt,
                        self => $self,
-                       nr => \(my $nr = 0),
                        -regen_fmt => "%u/?\n",
                };
                $sync->{art_end} = $art_end;
@@ -1206,6 +1205,7 @@ sub index_sync {
        my ($self, $opt) = @_;
        $opt //= {};
        local $self->{need_checkpoint} = 0;
+       local $self->{nrec} = 0;
        return xapian_only($self, $opt) if $opt->{xapian_only};
 
        my $epoch_max = $self->{ibx}->max_git_epoch // return;
@@ -1262,9 +1262,9 @@ sub index_sync {
        $self->{oidx}->rethread_done($opt) unless $sync->{quit};
        $self->done;
 
-       if (my $nr = $sync->{nr}) {
+       if (my $nrec = $self->{nrec}) {
                my $pr = $sync->{-opt}->{-progress};
-               $pr->('all.git '.sprintf($sync->{-regen_fmt}, $$nr)) if $pr;
+               $pr->('all.git '.sprintf($sync->{-regen_fmt}, $nrec)) if $pr;
        }
 
        my $quit_warn;