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-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 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 36ED61FB0B for ; Fri, 4 Dec 2020 22:03:50 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/5] nntp: xref_by_tc: simplify slightly Date: Fri, 4 Dec 2020 22:03:45 +0000 Message-Id: <20201204220349.4408-2-e@80x24.org> In-Reply-To: <20201204220349.4408-1-e@80x24.org> References: <20201204220349.4408-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can invalidate ibx->{newsgroup} at config load-time to avoid having to check ibx->{newsgroup} validity in To/Cc: matching. This saves us some hash lookups in all cases. --- lib/PublicInbox/NNTP.pm | 3 +-- lib/PublicInbox/NNTPD.pm | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index e0916011..6728f9c5 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -422,14 +422,13 @@ sub header_append ($$$) { sub xref_by_tc ($$$) { my ($xref, $pi_cfg, $smsg) = @_; my $by_addr = $pi_cfg->{-by_addr}; - my $groups = $pi_cfg->{-by_newsgroup}; my $mid = $smsg->{mid}; for my $f (qw(to cc)) { my @ibxs = map { $by_addr->{lc($_)} // () } (PublicInbox::Address::emails($smsg->{$f} // '')); for my $ibx (@ibxs) { - $groups->{my $ngname = $ibx->{newsgroup}} or next; + my $ngname = $ibx->{newsgroup} // next; next if defined $xref->{$ngname}; $xref->{$ngname} = eval { $ibx->mm->num_for($mid) }; } diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm index 967850e9..03c56db3 100644 --- a/lib/PublicInbox/NNTPD.pm +++ b/lib/PublicInbox/NNTPD.pm @@ -38,13 +38,18 @@ sub refresh_groups { my $groups = $pi_config->{-by_newsgroup}; # filled during each_inbox $pi_config->each_inbox(sub { my ($ibx) = @_; - my $ngname = $ibx->{newsgroup} // return; - if ($ibx->nntp_usable) { # only valid if msgmap and over works + my $ngname = $ibx->{newsgroup}; + if (defined($ngname) && $ibx->nntp_usable) { + # only valid if msgmap and over works # preload to avoid fragmentation: $ibx->description; $ibx->base_url; } else { delete $groups->{$ngname}; + delete $ibx->{newsgroup}; + # Note: don't be tempted to delete more for memory + # savings just yet: NNTP, IMAP, and WWW may all + # run in the same process someday. } }); $self->{groupnames} = [ sort(keys %$groups) ];