]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: use grep operation for wildmat matching
authorEric Wong <e@80x24.org>
Fri, 27 Nov 2020 09:52:46 +0000 (09:52 +0000)
committerEric Wong <e@80x24.org>
Sat, 28 Nov 2020 04:53:15 +0000 (04:53 +0000)
Based on experiences with the IMAP server, this ought to be
significantly faster (as to be demonstrated in the next
commit).

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

index b641bd23e5304f964586544dec4dd340e2f67eff..6822219646ffe1f5b5cae2177bbff99544cb255f 100644 (file)
@@ -136,29 +136,29 @@ sub list_headers ($;$) {
 sub list_active ($;$) {
        my ($self, $wildmat) = @_;
        wildmat2re($wildmat);
-       foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
-               $ng->{newsgroup} =~ $wildmat or next;
-               group_line($self, $ng);
+       my $groups = $self->{nntpd}->{groups};
+       for my $ngname (grep(/$wildmat/, @{$self->{nntpd}->{groupnames}})) {
+               group_line($self, $groups->{$ngname});
        }
 }
 
 sub list_active_times ($;$) {
        my ($self, $wildmat) = @_;
        wildmat2re($wildmat);
-       foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
-               $ng->{newsgroup} =~ $wildmat or next;
-               my $c = eval { $ng->uidvalidity } // time;
-               more($self, "$ng->{newsgroup} $c $ng->{-primary_address}");
+       my $groups = $self->{nntpd}->{groups};
+       for my $ngname (grep(/$wildmat/, @{$self->{nntpd}->{groupnames}})) {
+               my $ibx = $groups->{$ngname};
+               my $c = eval { $ibx->uidvalidity } // time;
+               more($self, "$ngname $c $ibx->{-primary_address}");
        }
 }
 
 sub list_newsgroups ($;$) {
        my ($self, $wildmat) = @_;
        wildmat2re($wildmat);
-       foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
-               $ng->{newsgroup} =~ $wildmat or next;
-               my $d = $ng->description;
-               more($self, "$ng->{newsgroup} $d");
+       my $groups = $self->{nntpd}->{groups};
+       for my $ngname (grep(/$wildmat/, @{$self->{nntpd}->{groupnames}})) {
+               more($self, "$ngname ".$groups->{$ngname}->description);
        }
 }
 
index 13b0f678284b284ed4c05b3cefc3beead125cd25..4de1944b27206c36e7afc6bce44353de532843ea 100644 (file)
@@ -60,7 +60,9 @@ sub refresh_groups {
                        delete $groups->{$ngname};
                }
        });
-       $self->{grouplist} = [ map { $groups->{$_} } sort(keys %$groups) ];
+       my @names = sort(keys %$groups);
+       $self->{grouplist} = [ map { $groups->{$_} } @names ];
+       $self->{groupnames} = \@names;
        $self->{pi_config} = $pi_config;
        # this will destroy old groups that got deleted
        $self->{groups} = $groups;