]> Sergey Matveev's repositories - public-inbox.git/commitdiff
inbox: drop memoization/preload, cleanup expires caches
authorEric Wong <e@80x24.org>
Tue, 28 Sep 2021 23:11:06 +0000 (23:11 +0000)
committerEric Wong <e@80x24.org>
Wed, 29 Sep 2021 00:08:34 +0000 (00:08 +0000)
cloneurl, description, and base_url are no longer memoized.  The
non-$env form of base_url is rare in WWW, and is fast enough to
not require memoization.

cloneurl and description are now expired during cleanup,
allowing admins to change these files without restarting
(or SIGHUP).

-altid_map is no longer cached nor memoized at all, since the
endpoint(s) which hit it seem rarely accessed.

nntp_url and imap_url are now cached (instead of memoized) in
case an inbox is unvisited for a long time.  They remain cached
since the truthiness check gets called in every per-inbox HTML
page, which can potentially be expensive.

lib/PublicInbox/Inbox.pm
lib/PublicInbox/WWW.pm
t/nntp.t

index 04b7d764197cfa6cc1563088d241621211abcf8d..c525f4d169d250fd6e007afc633edb844d5a4078 100644 (file)
@@ -33,7 +33,8 @@ sub do_cleanup {
        for my $git (@{$ibx->{-repo_objs}}) {
                $live = 1 if $git->cleanup(1);
        }
-       delete @$ibx{qw(over mm)};
+       delete @$ibx{qw(over mm description cloneurl
+                       -altid_map -imap_url -nntp_url)};
        PublicInbox::DS::add_uniq_timer($ibx+0, 5, \&do_cleanup, $ibx) if $live;
 }
 
@@ -219,15 +220,13 @@ sub base_url {
                return $url .= $self->{name} . '/';
        }
        # called from a non-PSGI environment (e.g. NNTP/POP3):
-       $self->{-base_url} ||= do {
-               my $url = $self->{url} // return undef;
-               $url = $url->[0] // return undef;
-               # expand protocol-relative URLs to HTTPS if we're
-               # not inside a web server
-               $url = "https:$url" if $url =~ m!\A//!;
-               $url .= '/' if $url !~ m!/\z!;
-               $url;
-       };
+       my $url = $self->{url} // return undef;
+       $url = $url->[0] // return undef;
+       # expand protocol-relative URLs to HTTPS if we're
+       # not inside a web server
+       substr($url, 0, 0, 'https:') if substr($url, 0, 2) eq '//';
+       $url .= '/' if substr($url, -1, 1) ne '/';
+       $url;
 }
 
 sub _x_url ($$$) {
@@ -350,7 +349,7 @@ sub modified {
 # (pathname is NOT public, but prefix is used for Xapian queries)
 sub altid_map ($) {
        my ($self) = @_;
-       $self->{-altid_map} //= eval {
+       eval {
                require PublicInbox::AltId;
                my $altid = $self->{altid} or return {};
                my %h = map {;
index a7c961f4982a962c43071035660c90ed3a697d0a..5e83f76915d5f1e0b2bcf1f3afafe09eb3c50af6 100644 (file)
@@ -173,18 +173,9 @@ sub preload {
                $self->cgit;
                $self->stylesheets_prepare($_) for ('', '../', '../../');
                $self->news_www;
-               $pi_cfg->each_inbox(\&preload_inbox);
        }
 }
 
-sub preload_inbox {
-       my $ibx = shift;
-       $ibx->altid_map;
-       $ibx->cloneurl;
-       $ibx->description;
-       $ibx->base_url;
-}
-
 # private functions below
 
 sub r404 {
index 5bad9dfe25fe204d5a998185b7546d0b8a580329..655af39825b2f514d621600399964db7ba4b450e 100644 (file)
--- a/t/nntp.t
+++ b/t/nntp.t
@@ -126,7 +126,6 @@ use PublicInbox::Config;
        is_deeply([ $mime->header('Xref') ], [ 'example.com test:1' ],
                'Xref: set');
 
-       $ibx->{-base_url} = 'http://mirror.example.com/m/';
        $smsg->{num} = 2;
        PublicInbox::NNTP::set_nntp_headers($hdr, $smsg);
        is_deeply([ $mime->header('Message-ID') ], [ "<$mid>" ],