]> Sergey Matveev's repositories - public-inbox.git/commitdiff
v2writable: only load Xapian when a shard is found
authorEric Wong <e@yhbt.net>
Sun, 24 May 2020 03:06:37 +0000 (03:06 +0000)
committerEric Wong <e@yhbt.net>
Mon, 25 May 2020 09:12:19 +0000 (09:12 +0000)
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

index 513e9f230117893ec9f9d7e381bfc05d1baf1a82..b393b31f0e205f3191169762fbd1af9d76fa3d52 100644 (file)
@@ -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++;