user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] v2writable: only load Xapian when a shard is found
@ 2020-05-24  3:06 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2020-05-24  3:06 UTC (permalink / raw)
  To: meta

We don't need to load Xapian until we have a directory
which looks like a shard, otherwise we're wasting cycles
on memory when running short-lived processes.
---
 lib/PublicInbox/V2Writable.pm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 513e9f23..b393b31f 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -75,11 +75,14 @@ sub count_shards ($) {
 	# Also, shard count may change while -watch is running
 	# due to "xcpdb --reshard"
 	if (-d $xpfx) {
-		require PublicInbox::Search;
-		PublicInbox::Search::load_xapian();
-		my $XapianDatabase = $PublicInbox::Search::X{Database};
+		my $XapianDatabase;
 		foreach my $shard (<$xpfx/*>) {
 			-d $shard && $shard =~ m!/[0-9]+\z! or next;
+			$XapianDatabase //= do {
+				require PublicInbox::Search;
+				PublicInbox::Search::load_xapian();
+				$PublicInbox::Search::X{Database};
+			};
 			eval {
 				$XapianDatabase->new($shard)->close;
 				$n++;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-05-24  3:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-24  3:06 [PATCH] v2writable: only load Xapian when a shard is found Eric Wong

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).