user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/3] inbox: drop memoization/preload, cleanup expires caches
Date: Tue, 28 Sep 2021 23:11:06 +0000	[thread overview]
Message-ID: <20210928231106.5166-4-e@80x24.org> (raw)
In-Reply-To: <20210928231106.5166-1-e@80x24.org>

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 | 21 ++++++++++-----------
 lib/PublicInbox/WWW.pm   |  9 ---------
 t/nntp.t                 |  1 -
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 04b7d764..c525f4d1 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -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 {;
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index a7c961f4..5e83f769 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -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 {
diff --git a/t/nntp.t b/t/nntp.t
index 5bad9dfe..655af398 100644
--- 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>" ],

      parent reply	other threads:[~2021-09-28 23:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28 23:11 [PATCH 0/3] www: more aggressive cleanup of SQLite DBs Eric Wong
2021-09-28 23:11 ` [PATCH 1/3] www: do not bump {over} refcnt on long responses Eric Wong
2021-09-28 23:11 ` [PATCH 2/3] inbox: rewrite cleanup to be more aggressive Eric Wong
2021-09-28 23:11 ` 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=20210928231106.5166-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH 3/3] inbox: drop memoization/preload, cleanup expires caches' \
    /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

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

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).