]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: xref_by_tc: simplify slightly
authorEric Wong <e@80x24.org>
Fri, 4 Dec 2020 22:03:45 +0000 (22:03 +0000)
committerEric Wong <e@80x24.org>
Sat, 5 Dec 2020 21:41:52 +0000 (21:41 +0000)
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
lib/PublicInbox/NNTPD.pm

index e0916011902e6279c8f07db86bdf4b22cf6c0526..6728f9c528665bd0fe28b99cfa0fc9a829b3518e 100644 (file)
@@ -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) };
                }
index 967850e9d6ec7e713532fe917e3974f4f36a96c4..03c56db30727ec2dbee9e205592bd459f78ef892 100644 (file)
@@ -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) ];