]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: tie ALE lifetime to config file
authorEric Wong <e@80x24.org>
Sat, 20 Mar 2021 10:04:07 +0000 (19:04 +0900)
committerEric Wong <e@80x24.org>
Sun, 21 Mar 2021 09:45:50 +0000 (09:45 +0000)
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
lib/PublicInbox/LeiALE.pm
lib/PublicInbox/LeiExternal.pm
lib/PublicInbox/LeiQuery.pm
t/lei_xsearch.t

index 0da26a32825755c7f3534d2c50b9c70e04fc06f0..72a0e52c62d148a7b61da1ce063c0ac26e81583d 100644 (file)
@@ -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);
        };
 }
 
index bdb50a1a08a2b34b16531d5f9e1ca96f9ab1f404..45748435b53407995a66f337359b6833ba40eb6b 100644 (file)
@@ -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
index aa09be9ea980035d4a2024497c69d025c7bf523e..b5dd85e158b18f007cf53f97e6e6c08f896430e0 100644 (file)
@@ -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);
 }
 
index 007e35fc41cf061b4ce963afc0ba99e0fda37d94..148e8524d6d97b716885ba8e0eff59d693b14225 100644 (file)
@@ -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) {
index 68211d181339d574b69d43b3681b1fe86a8623b0..e56b28204ca13f1e0fb616a0c2c60f24d48798e1 100644 (file)
@@ -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');