From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5E5971F452 for ; Thu, 24 Aug 2023 01:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1692840156; bh=7etxvUL7w23bUIDLVldDFjLfx3wGdirprSppr8ES3Mg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=E175nIeRFkgwe+AJxS5CX1MdbpVyqd7VNLtiDI0Pijo0BjxxMO58MM2CDrJFSaY8V Hbf43O5TgLNg/yO0WjvhcI782HaKOvUfBGV5A/utwYSkd5y9tsOMCY5MtUMvNnsU1R 6JBeZUC7eMuHkmT2G2hHdaDQuIBnyi5cJhBScmFI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/7] search: hoist out shards_dir for future use Date: Thu, 24 Aug 2023 01:22:30 +0000 Message-Id: <20230824012236.3968030-2-e@80x24.org> In-Reply-To: <20230824012236.3968030-1-e@80x24.org> References: <20230824012236.3968030-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This will be useful for internal tooling and APIs. --- 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 b2de3450..1559d9b3 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; }