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 35F071FC0D for ; Fri, 27 Nov 2020 09:52:55 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 04/12] nntp: use grep operation for wildmat matching Date: Fri, 27 Nov 2020 09:52:46 +0000 Message-Id: <20201127095254.21624-5-e@80x24.org> In-Reply-To: <20201127095254.21624-1-e@80x24.org> References: <20201127095254.21624-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 22 +++++++++++----------- lib/PublicInbox/NNTPD.pm | 4 +++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index b641bd23..68222196 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -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); } } diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm index 13b0f678..4de1944b 100644 --- a/lib/PublicInbox/NNTPD.pm +++ b/lib/PublicInbox/NNTPD.pm @@ -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;