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.
# Also, shard count may change while -watch is running
# due to "xcpdb --reshard"
if (-d $xpfx) {
# 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};
foreach my $shard (<$xpfx/*>) {
-d $shard && $shard =~ m!/[0-9]+\z! or next;
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++;
eval {
$XapianDatabase->new($shard)->close;
$n++;