]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: reuse LeiStore object on config changes
authorEric Wong <e@80x24.org>
Mon, 15 Mar 2021 09:32:06 +0000 (07:32 -0200)
committerEric Wong <e@80x24.org>
Mon, 15 Mar 2021 19:26:58 +0000 (15:26 -0400)
Unless leistore.dir changes, the same LeiStore object
is should remain reusable and accessible to any clients

This seems to fix problems with t/lei-q-remote-import.t
occasionally getting stuck

lib/PublicInbox/LEI.pm

index 59a3338c08a69a9415190546b122d06bc14eff3f..31d5b838e7b66c44d4612d5b8dbb598950a86f22 100644 (file)
@@ -606,8 +606,10 @@ sub _lei_cfg ($;$) {
        my $f = _config_path($self);
        my @st = stat($f);
        my $cur_st = @st ? pack('dd', $st[10], $st[7]) : ''; # 10:ctime, 7:size
+       my ($sto, $sto_dir);
        if (my $cfg = $PATH2CFG{$f}) { # reuse existing object in common case
                return ($self->{cfg} = $cfg) if $cur_st eq $cfg->{-st};
+               ($sto, $sto_dir) = @$cfg{qw(-lei_store leistore.dir)};
        }
        if (!@st) {
                unless ($creat) {
@@ -625,6 +627,10 @@ sub _lei_cfg ($;$) {
        bless $cfg, 'PublicInbox::Config';
        $cfg->{-st} = $cur_st;
        $cfg->{'-f'} = $f;
+       if ($sto && File::Spec->canonpath($sto_dir) eq
+                       File::Spec->canonpath($cfg->{'leistore.dir'})) {
+               $cfg->{-lei_store} = $sto;
+       }
        $self->{cfg} = $PATH2CFG{$f} = $cfg;
 }