]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntpd: remove redundant {groups} shortcut
authorEric Wong <e@80x24.org>
Sat, 28 Nov 2020 05:09:16 +0000 (05:09 +0000)
committerEric Wong <e@80x24.org>
Sun, 29 Nov 2020 02:25:51 +0000 (02:25 +0000)
It's not worth confusing hackers reading the source to have
two ways to access the same (large) hash table.  So just
go through PublicInbox::Config objects for now since the
extra hash lookup isn't going to be noticeable.

I've also started favoring "for" instead of "foreach"
since they're the equivalent perlop and less wear on
my fingers + keyboard.

lib/PublicInbox/NNTP.pm
lib/PublicInbox/NNTPD.pm

index d314a3d1ebcf0bc74001593319b93448c203cb3d..3b16a66abad72181ef940339ce9e2691d169a6ce 100644 (file)
@@ -321,7 +321,7 @@ sub ngpat2re (;$) {
 sub newnews_i {
        my ($self, $names, $ts, $prev) = @_;
        my $ngname = $names->[0];
-       if (my $ibx = $self->{nntpd}->{groups}->{$ngname}) {
+       if (my $ibx = $self->{nntpd}->{pi_config}->{-by_newsgroup}->{$ngname}) {
                if (my $over = $ibx->over) {
                        my $msgs = $over->query_ts($ts, $$prev);
                        if (scalar @$msgs) {
@@ -360,13 +360,13 @@ sub cmd_newnews ($$$$;$$) {
 
 sub cmd_group ($$) {
        my ($self, $group) = @_;
-       my $no_such = '411 no such news group';
        my $nntpd = $self->{nntpd};
-       my $ng = $nntpd->{groups}->{$group} or return $no_such;
+       my $ibx = $nntpd->{pi_config}->{-by_newsgroup}->{$group} or
+               return '411 no such news group';
        $nntpd->idler_start;
 
-       $self->{ng} = $ng;
-       my ($min, $max) = $ng->mm->minmax;
+       $self->{ng} = $ibx;
+       my ($min, $max) = $ibx->mm->minmax;
        $self->{article} = $min;
        my $est_size = $max - $min;
        "211 $est_size $min $max $group";
@@ -743,7 +743,7 @@ EOF
                }
                # no warning here, $mid is just invalid
        } else { # slow path for non-ALL users
-               foreach my $ibx (values %{$self->{nntpd}->{groups}}) {
+               for my $ibx (values %{$pi_cfg->{-by_newsgroup}}) {
                        next if defined $self_ng && $ibx eq $self_ng;
                        my $n = $ibx->mm->num_for($mid);
                        return ($ibx, $n) if defined $n;
index 33bc5fda7a9a936e0fc95c28a14d91113d3bda31..5e287857232093a1257c84e24710facbe5472b9a 100644 (file)
@@ -60,9 +60,8 @@ sub refresh_groups {
                }
        });
        $self->{groupnames} = [ sort(keys %$groups) ];
-       $self->{pi_config} = $pi_config;
        # this will destroy old groups that got deleted
-       $self->{groups} = $groups;
+       $self->{pi_config} = $pi_config;
 }
 
 sub idler_start {