From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/5] imap: mailboxes list across listeners
Date: Mon, 8 Aug 2022 23:53:10 +0000 [thread overview]
Message-ID: <20220808235311.2006279-5-e@80x24.org> (raw)
In-Reply-To: <20220808235311.2006279-1-e@80x24.org>
Since IMAP mailbox lists are tied to the PublicInbox::Config
object, we can share them the same way the config object is
shared when an -imapd or -netd instance has multiple listeners.
This ought to reduce memory use and startup time when binding
multiple sockets which share a common config file.
---
lib/PublicInbox/IMAPD.pm | 49 ++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 22 deletions(-)
diff --git a/lib/PublicInbox/IMAPD.pm b/lib/PublicInbox/IMAPD.pm
index dd0d2c53..ba6ad05d 100644
--- a/lib/PublicInbox/IMAPD.pm
+++ b/lib/PublicInbox/IMAPD.pm
@@ -23,7 +23,7 @@ sub new {
}, $class;
}
-sub imapd_refresh_ibx { # pi_cfg->each_inbox cb
+sub _refresh_ibx { # pi_cfg->each_inbox cb
my ($ibx, $imapd, $cache, $dummies) = @_;
my $ngname = $ibx->{newsgroup} // return;
@@ -56,27 +56,32 @@ sub imapd_refresh_ibx { # pi_cfg->each_inbox cb
sub refresh_groups {
my ($self, $sig) = @_;
my $pi_cfg = PublicInbox::Config->new;
- my $mailboxes = $self->{mailboxes} = {};
- my $cache = eval { $pi_cfg->ALL->misc->nntpd_cache_load } // {};
- my $dummies = {};
- $pi_cfg->each_inbox(\&imapd_refresh_ibx, $self, $cache, $dummies);
- %$dummies = (%$dummies, %$mailboxes);
- $mailboxes = $self->{mailboxes} = $dummies;
- @{$self->{mailboxlist}} = map { $_->[2] }
- sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] }
- map {
- my $u = $_; # capitalize "INBOX" for user-familiarity
- $u =~ s/\Ainbox(\.|\z)/INBOX$1/i;
- if ($mailboxes->{$_} == $dummy) {
- [ $u, -1,
- qq[* LIST (\\HasChildren) "." $u\r\n]]
- } else {
- $u =~ /\A(.+)\.([0-9]+)\z/ or
- die "BUG: `$u' has no slice digit(s)";
- [ $1, $2 + 0,
- qq[* LIST (\\HasNoChildren) "." $u\r\n] ]
- }
- } keys %$mailboxes;
+ $self->{mailboxes} = $pi_cfg->{-imap_mailboxes} // do {
+ my $mailboxes = $self->{mailboxes} = {};
+ my $cache = eval { $pi_cfg->ALL->misc->nntpd_cache_load } // {};
+ my $dummies = {};
+ $pi_cfg->each_inbox(\&_refresh_ibx, $self, $cache, $dummies);
+ %$mailboxes = (%$dummies, %$mailboxes);
+ @{$pi_cfg->{-imap_mailboxlist}} = map { $_->[2] }
+ sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] }
+ map {
+ # capitalize "INBOX" for user-familiarity
+ my $u = $_;
+ $u =~ s/\Ainbox(\.|\z)/INBOX$1/i;
+ if ($mailboxes->{$_} == $dummy) {
+ [ $u, -1,
+ qq[* LIST (\\HasChildren) "." $u\r\n]]
+ } else {
+ $u =~ /\A(.+)\.([0-9]+)\z/ or die
+"BUG: `$u' has no slice digit(s)";
+ [ $1, $2 + 0, '* LIST '.
+ qq[(\\HasNoChildren) "." $u\r\n] ]
+ }
+ } keys %$mailboxes;
+ $pi_cfg->{-imap_mailboxes} = $mailboxes;
+ };
+ $self->{mailboxlist} = $pi_cfg->{-imap_mailboxlist} //
+ die 'BUG: no mailboxlist';
$self->{pi_cfg} = $pi_cfg;
if (my $idler = $self->{idler}) {
$idler->refresh($pi_cfg);
next prev parent reply other threads:[~2022-08-08 23:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-08 23:53 [PATCH 0/5] daemon/netd-related improvements Eric Wong
2022-08-08 23:53 ` [PATCH 1/5] daemon: use default address + well-known ports for scheme Eric Wong
2022-08-08 23:53 ` [PATCH 2/5] daemon: use per-listener SIG{__WARN__} callbacks Eric Wong
2022-08-08 23:53 ` [PATCH 3/5] daemon: cleanup internal data structures Eric Wong
2022-08-08 23:53 ` Eric Wong [this message]
2022-08-08 23:53 ` [PATCH 5/5] imapd|nntpd: drop ->base_url preload Eric Wong
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=20220808235311.2006279-5-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public 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).