From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CD4571F61A for ; Mon, 8 Aug 2022 23:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1660002791; bh=OXIFHPMMLHhPCQspIflOKsAIbfmn+GcgjBICxuIpiYA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BgXCl0BCxtOpmmb4wt6D88gRAH8SGBtuFJnPLzHpn/OWYGTWe3yLw58MsIbBHNDoV YvC8ygqMwQO6XF7QQly3o8ajnnB1YgtD46HXYUHZcz9k4ea2yfVu0Rys2eDAsjvAfJ QXRRX6Hs8q05LwK0MBVWnCE2hic4CFj8qcr6YHoM= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/5] imap: mailboxes list across listeners Date: Mon, 8 Aug 2022 23:53:10 +0000 Message-Id: <20220808235311.2006279-5-e@80x24.org> In-Reply-To: <20220808235311.2006279-1-e@80x24.org> References: <20220808235311.2006279-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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);