unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 5/5] lei: tie ALE lifetime to config file
Date: Sat, 20 Mar 2021 19:04:07 +0900	[thread overview]
Message-ID: <20210320100407.15713-6-e@80x24.org> (raw)
In-Reply-To: <20210320100407.15713-1-e@80x24.org>

This should make a future change to "lei import" work more
nicely, since we'll be needing ALE to vivify external-only
messages upon explicit "lei import".
---
 lib/PublicInbox/LEI.pm         |  3 +--
 lib/PublicInbox/LeiALE.pm      | 19 ++++++++++++++++---
 lib/PublicInbox/LeiExternal.pm |  6 ------
 lib/PublicInbox/LeiQuery.pm    |  4 ----
 t/lei_xsearch.t                |  2 +-
 5 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 0da26a32..72a0e52c 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -108,8 +108,7 @@ sub ale {
 	my ($self) = @_;
 	$self->{ale} //= do {
 		require PublicInbox::LeiALE;
-		PublicInbox::LeiALE->new(cache_dir($self).
-					'/all_locals_ever.git');
+		$self->_lei_cfg(1)->{ale} //= PublicInbox::LeiALE->new($self);
 	};
 }
 
diff --git a/lib/PublicInbox/LeiALE.pm b/lib/PublicInbox/LeiALE.pm
index bdb50a1a..45748435 100644
--- a/lib/PublicInbox/LeiALE.pm
+++ b/lib/PublicInbox/LeiALE.pm
@@ -11,16 +11,29 @@ use v5.10.1;
 use parent qw(PublicInbox::LeiSearch PublicInbox::Lock);
 use PublicInbox::Git;
 use PublicInbox::Import;
+use PublicInbox::LeiXSearch;
 use Fcntl qw(SEEK_SET);
 
-sub new {
-	my ($cls, $d) = @_;
+sub _new {
+	my ($d) = @_;
 	PublicInbox::Import::init_bare($d, 'ale');
 	bless {
 		git => PublicInbox::Git->new($d),
 		lock_path => "$d/lei_ale.state", # dual-duty lock + state
 		ibxish => [], # Inbox and ExtSearch (and LeiSearch) objects
-	}, $cls;
+	}, __PACKAGE__
+}
+
+sub new {
+	my ($self, $lei) = @_;
+	ref($self) or $self = _new($lei->cache_dir . '/all_locals_ever.git');
+	my $lxs = PublicInbox::LeiXSearch->new;
+	$lxs->prepare_external($lei->_lei_store(1)->search);
+	for my $loc ($lei->externals_each) { # locals only
+		$lxs->prepare_external($loc) if -d $loc;
+	}
+	$self->refresh_externals($lxs);
+	$self;
 }
 
 sub over {} # undef for xoids_for
diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm
index aa09be9e..b5dd85e1 100644
--- a/lib/PublicInbox/LeiExternal.pm
+++ b/lib/PublicInbox/LeiExternal.pm
@@ -139,12 +139,6 @@ sub add_external_finish {
 	my $key = "external.$location.boost";
 	my $cur_boost = $cfg->{$key};
 	return if defined($cur_boost) && $cur_boost == $new_boost; # idempotent
-	if (-d $location) {
-		require PublicInbox::LeiXSearch;
-		my $lxs = PublicInbox::LeiXSearch->new;
-		$lxs->prepare_external($location);
-		$self->ale->refresh_externals($lxs);
-	}
 	$self->lei_config($key, $new_boost);
 }
 
diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm
index 007e35fc..148e8524 100644
--- a/lib/PublicInbox/LeiQuery.pm
+++ b/lib/PublicInbox/LeiQuery.pm
@@ -57,10 +57,6 @@ sub lei_q {
 	}
 	if ($opt->{'local'} //= scalar(@only) ? 0 : 1) {
 		$lxs->prepare_external($lse);
-	} else {
-		my $tmp = PublicInbox::LeiXSearch->new;
-		$tmp->prepare_external($lse);
-		$self->ale->refresh_externals($tmp);
 	}
 	if (@only) {
 		for my $loc (@only) {
diff --git a/t/lei_xsearch.t b/t/lei_xsearch.t
index 68211d18..e56b2820 100644
--- a/t/lei_xsearch.t
+++ b/t/lei_xsearch.t
@@ -90,7 +90,7 @@ is($lxs->over, undef, '->over fails');
 	my $mitem = ($mset->items)[0];
 	my $smsg = $lxs->smsg_for($mitem) or BAIL_OUT 'smsg_for broken';
 
-	my $ale = PublicInbox::LeiALE->new("$home/ale");
+	my $ale = PublicInbox::LeiALE::_new("$home/ale");
 	$ale->refresh_externals($lxs);
 	my $exp = [ $smsg->{blob}, 'blob', -s 't/utf8.eml' ];
 	is_deeply([ $ale->git->check($smsg->{blob}) ], $exp, 'ale->git->check');

      parent reply	other threads:[~2021-03-20 10:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-20 10:04 [PATCH 0/5] lei: preserve keywords across queries Eric Wong
2021-03-20 10:04 ` [PATCH 1/5] lei: All Local Externals: bare git dir for alternates Eric Wong
2021-03-20 10:04 ` [PATCH 2/5] lei q: support vmd for external-only messages Eric Wong
2021-03-20 10:04 ` [PATCH 3/5] lei q: put keywords on one line in --pretty output Eric Wong
2021-03-20 10:04 ` [PATCH 4/5] lei_to_mail: match mutt order of status headers Eric Wong
2021-03-20 10:04 ` Eric Wong [this message]

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

  List information: https://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20210320100407.15713-6-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.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).