dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] search: hoist out shards_dir for future use
Date: Sat, 19 Aug 2023 21:36:27 +0000	[thread overview]
Message-ID: <20230819213627.3477610-1-e@80x24.org> (raw)

---
 lib/PublicInbox/Search.pm | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index a4fef17b..c66f0559 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -202,28 +202,32 @@ sub xdir ($;$) {
 	}
 }
 
-# returns all shards as separate Xapian::Database objects w/o combining
-sub xdb_shards_flat ($) {
+# returns shard directories as an array of strings, does not verify existence
+sub shard_dirs ($) {
 	my ($self) = @_;
 	my $xpfx = $self->{xpfx};
-	my (@xdb, $slow_phrase);
-	load_xapian();
-	$self->{qp_flags} //= $QP_FLAGS;
-	if ($xpfx =~ m!/xapian[0-9]+\z!) { # v1
-		@xdb = ($X{Database}->new($xpfx));
-		$self->{qp_flags} |= FLAG_PHRASE() if !-f "$xpfx/iamchert";
-	} else { # v2, eidx, cidx
+	if ($xpfx =~ m!/xapian[0-9]+\z!) { # v1 inbox
+		($xpfx);
+	} else { # v2 inbox, eidx, cidx
 		opendir(my $dh, $xpfx) or return (); # not initialized yet
 		# We need numeric sorting so shard[0] is first for reading
 		# Xapian metadata, if needed
 		my $last = max(grep(/\A[0-9]+\z/, readdir($dh))) // return ();
-		@xdb = map {
-			my $shard_dir = "$xpfx/$_";
-			$slow_phrase ||= -f "$shard_dir/iamchert";
-			$X{Database}->new($shard_dir);
-		} (0..$last);
-		$self->{qp_flags} |= FLAG_PHRASE() if !$slow_phrase;
+		map { "$xpfx/$_" } (0..$last);
 	}
+}
+
+# returns all shards as separate Xapian::Database objects w/o combining
+sub xdb_shards_flat ($) {
+	my ($self) = @_;
+	load_xapian();
+	$self->{qp_flags} //= $QP_FLAGS;
+	my $slow_phrase;
+	my @xdb = map {
+		$slow_phrase ||= -f "$_/iamchert";
+		$X{Database}->new($_); # raises if missing
+	} shard_dirs($self);
+	$self->{qp_flags} |= FLAG_PHRASE() if !$slow_phrase;
 	@xdb;
 }
 

                 reply	other threads:[~2023-08-19 21:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=20230819213627.3477610-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.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.
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).