]> Sergey Matveev's repositories - public-inbox.git/commitdiff
inbox: delay ->version detection
authorEric Wong <e@80x24.org>
Mon, 21 Dec 2020 07:51:18 +0000 (07:51 +0000)
committerEric Wong <e@80x24.org>
Mon, 21 Dec 2020 21:51:55 +0000 (21:51 +0000)
Our read-only code won't need to know the version until an inbox
is accessed.  This is a small step towards eliminating many
stat() calls on read-only daemon startup.

lib/PublicInbox/Inbox.pm

index 8a3a01940a008473bebab3d307608f1d432762f8..863a5de442187ca7d7e946e3076b4d4e936e5b8a 100644 (file)
@@ -109,10 +109,6 @@ sub new {
                delete $opts->{feedmax};
        }
        $opts->{nntpserver} ||= $pi_cfg->{'publicinbox.nntpserver'};
-       my $dir = $opts->{inboxdir};
-       if (defined $dir && -f "$dir/inbox.lock") {
-               $opts->{version} = 2;
-       }
 
        # allow any combination of multi-line or comma-delimited hide entries
        my $hide = {};
@@ -125,7 +121,9 @@ sub new {
        bless $opts, $class;
 }
 
-sub version { $_[0]->{version} // 1 }
+sub version {
+       $_[0]->{version} //= -f "$_[0]->{inboxdir}/inbox.lock" ? 2 : 1
+}
 
 sub git_epoch {
        my ($self, $epoch) = @_; # v2-only, callers always supply $epoch