user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/3] cindex: avoid unneeded and redundant `local' calls
Date: Tue, 21 Nov 2023 12:43:13 +0000	[thread overview]
Message-ID: <20231121124315.1775613-2-e@80x24.org> (raw)
In-Reply-To: <20231121124315.1775613-1-e@80x24.org>

We only set $MAX_SIZE at startup, and there's no need to
use a local $self->{roots} for the per-repo roots array.
---
 lib/PublicInbox/CodeSearchIdx.pm | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm
index 54a2ba22..bbccc0e3 100644
--- a/lib/PublicInbox/CodeSearchIdx.pm
+++ b/lib/PublicInbox/CodeSearchIdx.pm
@@ -152,8 +152,8 @@ EOM
 # TODO: may be used for reshard/compact
 sub count_shards { scalar($_[0]->xdb_shards_flat) }
 
-sub update_commit ($$) {
-	my ($self, $cmt) = @_; # fields from @FMT
+sub update_commit ($$$) {
+	my ($self, $cmt, $roots) = @_; # fields from @FMT
 	my $x = 'Q'.$cmt->{H};
 	my ($docid, @extra) = sort { $a <=> $b } docids_by_postlist($self, $x);
 	@extra and warn "W: $cmt->{H} indexed multiple times, pruning ",
@@ -161,7 +161,7 @@ sub update_commit ($$) {
 	$self->{xdb}->delete_document($_) for @extra;
 	my $doc = $PublicInbox::Search::X{Document}->new;
 	$doc->add_boolean_term($x);
-	$doc->add_boolean_term('G'.$_) for @{$self->{roots}};
+	$doc->add_boolean_term('G'.$_) for @$roots;
 	$doc->add_boolean_term('XP'.$_) for split(/ /, $cmt->{P});
 	$doc->add_boolean_term('T'.'c');
 
@@ -277,9 +277,7 @@ sub cidx_read_log_p {
 	my ($self, $log_p, $rd) = @_;
 	my $git = delete $log_p->{git} // die 'BUG: no {git}';
 	local $self->{current_info} = "$git->{git_dir} [$self->{shard}]";
-	local $self->{roots} = delete $log_p->{roots} // die 'BUG: no {roots}';
-
-	local $MAX_SIZE = $self->{-opt}->{max_size};
+	my $roots = delete $log_p->{roots} // die 'BUG: no {roots}';
 	# local-ized in parent before fork
 	$TXN_BYTES = $BATCH_BYTES;
 	local $self->{git} = $git; # for patchid
@@ -308,7 +306,7 @@ sub cidx_read_log_p {
 			cidx_ckpoint($self, "[$self->{shard}] $nr");
 			$TXN_BYTES -= $len; # len may be huge, >TXN_BYTES;
 		}
-		update_commit($self, $cmt);
+		update_commit($self, $cmt, $roots);
 		++$nr;
 		cidx_ckpoint($self, "[$self->{shard}] $nr") if $TXN_BYTES <= 0;
 		$/ = $FS;
@@ -1143,6 +1141,7 @@ sub cidx_run { # main entry point
 		@ID2ROOT, $XHC, @SORT, $GITS_NR);
 	local $BATCH_BYTES = $self->{-opt}->{batch_size} //
 				$PublicInbox::SearchIdx::BATCH_BYTES;
+	local $MAX_SIZE = $self->{-opt}->{max_size};
 	local $self->{ASSOC_PFX} = \@ASSOC_PFX;
 	local $self->{PENDING} = {};
 	local $self->{-pi_cfg};

  reply	other threads:[~2023-11-21 12:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 12:43 [PATCH 0/3] cindex: rename `associate' to `join' Eric Wong
2023-11-21 12:43 ` Eric Wong [this message]
2023-11-21 12:43 ` [PATCH 2/3] doc/cindex: point no-fsync,dangerous to -index(1) Eric Wong
2023-11-21 12:43 ` [PATCH 3/3] cindex: rename --associate to --join, test w/ real repos Eric Wong
2023-11-21 18:53   ` [squash 4/3] t/cindex-join: fix alternates setup Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231121124315.1775613-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).