user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 5/5] nntpd: remove redundant {groups} shortcut
Date: Sat, 28 Nov 2020 05:09:16 +0000	[thread overview]
Message-ID: <20201128050916.5586-6-e@80x24.org> (raw)
In-Reply-To: <20201128050916.5586-1-e@80x24.org>

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  | 12 ++++++------
 lib/PublicInbox/NNTPD.pm |  3 +--
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index d314a3d1..3b16a66a 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -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;
diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm
index 33bc5fda..5e287857 100644
--- a/lib/PublicInbox/NNTPD.pm
+++ b/lib/PublicInbox/NNTPD.pm
@@ -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 {

      parent reply	other threads:[~2020-11-28  5:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-28  5:09 [PATCH 0/5] nntp: round 2 of ->ALL extindex speedups Eric Wong
2020-11-28  5:09 ` [PATCH 1/5] nntp: NEWGROUPS uses long_response Eric Wong
2020-11-28  5:09 ` [PATCH 2/5] nntp: speed up mid_lookup() using ->ALL extindex Eric Wong
2020-11-28  5:09 ` [PATCH 3/5] nntp: art_lookup: use mid_lookup and simplify Eric Wong
2020-11-28  5:09 ` [PATCH 4/5] nntp: XPATH uses ->ALL extindex, too Eric Wong
2020-11-28  5:09 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201128050916.5586-6-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).