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 1/3] inbox: streamline ->nntp_url
Date: Thu, 16 Sep 2021 00:26:51 +0000	[thread overview]
Message-ID: <20210916002653.12188-2-e@80x24.org> (raw)
In-Reply-To: <20210916002653.12188-1-e@80x24.org>

We no longer waste a precious hash slot for a per-Inbox
{nntpserver} if it's only configured globally for all inboxes.
---
 lib/PublicInbox/Config.pm  |  4 ++--
 lib/PublicInbox/Inbox.pm   |  9 +++------
 lib/PublicInbox/WwwText.pm |  4 ++--
 t/config.t                 | 13 +++++++++----
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index ee5322fe..5e7a9f2b 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -424,7 +424,7 @@ sub _fill_ibx {
 	my ($self, $name) = @_;
 	my $pfx = "publicinbox.$name";
 	my $ibx = {};
-	for my $k (qw(watch nntpserver)) {
+	for my $k (qw(watch)) {
 		my $v = $self->{"$pfx.$k"};
 		$ibx->{$k} = $v if defined $v;
 	}
@@ -451,7 +451,7 @@ sub _fill_ibx {
 	# TODO: more arrays, we should support multi-value for
 	# more things to encourage decentralization
 	for my $k (qw(address altid nntpmirror coderepo hide listid url
-			infourl watchheader)) {
+			infourl watchheader nntpserver)) {
 		my $v = $self->{"$pfx.$k"} // next;
 		$ibx->{$k} = _array($v);
 	}
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index b0bb9dcc..f234b96f 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -109,8 +109,6 @@ sub new {
 	} else {
 		delete $opts->{feedmax};
 	}
-	$opts->{nntpserver} ||= $pi_cfg->{'publicinbox.nntpserver'};
-
 	# allow any combination of multi-line or comma-delimited hide entries
 	my $hide = {};
 	if (defined(my $h = $opts->{hide})) {
@@ -261,22 +259,21 @@ sub base_url {
 }
 
 sub nntp_url {
-	my ($self) = @_;
+	my ($self, $ctx) = @_;
 	$self->{-nntp_url} ||= do {
 		# no checking for nntp_usable here, we can point entirely
 		# to non-local servers or users run by a different user
-		my $ns = $self->{nntpserver};
+		my $ns = $self->{nntpserver} //
+		       $ctx->{www}->{pi_cfg}->get_all('publicinbox.nntpserver');
 		my $group = $self->{newsgroup};
 		my @urls;
 		if ($ns && $group) {
-			$ns = [ $ns ] if ref($ns) ne 'ARRAY';
 			@urls = map {
 				my $u = m!\Anntps?://! ? $_ : "nntp://$_";
 				$u .= '/' if $u !~ m!/\z!;
 				$u.$group;
 			} @$ns;
 		}
-
 		my $mirrors = $self->{nntpmirror};
 		if ($mirrors) {
 			my @m;
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index fabe39f6..177d55e4 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -210,7 +210,7 @@ EOF
 		defined(my $v = $ibx->{$k}) or next;
 		$$txt .= "\t$k = $v\n";
 	}
-	$$txt .= "\tnntpmirror = $_\n" for (@{$ibx->nntp_url});
+	$$txt .= "\tnntpmirror = $_\n" for (@{$ibx->nntp_url($ctx)});
 	_coderepo_config($ctx, $txt);
 	1;
 }
@@ -343,7 +343,7 @@ EOM
 Example config snippet for mirrors: $cfg_link
 EOF
 	if ($ibx->can('nntp_url')) {
-		my $nntp = $ibx->nntp_url;
+		my $nntp = $ibx->nntp_url($ctx);
 		if (scalar @$nntp) {
 			$$txt .= "\n";
 			$$txt .= @$nntp == 1 ? 'Newsgroup' : 'Newsgroups are';
diff --git a/t/config.t b/t/config.t
index 877e5d5d..2b02f063 100644
--- a/t/config.t
+++ b/t/config.t
@@ -43,7 +43,6 @@ my ($tmpdir, $for_destroy) = tmpdir();
 		-primary_address => 'meta@public-inbox.org',
 		'name' => 'meta',
 		-httpbackend_limiter => undef,
-		nntpserver => undef,
 	}, "lookup matches expected output");
 
 	is($cfg->lookup('blah@example.com'), undef,
@@ -60,7 +59,6 @@ my ($tmpdir, $for_destroy) = tmpdir();
 		'name' => 'test',
 		'url' => [ 'http://example.com/test' ],
 		-httpbackend_limiter => undef,
-		nntpserver => undef,
 	}, "lookup matches expected output for test");
 }
 
@@ -99,20 +97,27 @@ EOF
 	my $str = <<EOF;
 $pfx.address=test\@example.com
 $pfx.inboxdir=/path/to/non/existent
+$pfx.newsgroup=inbox.test
 publicinbox.nntpserver=news.example.com
 EOF
 	my $cfg = PublicInbox::Config->new(\$str);
 	my $ibx = $cfg->lookup_name('test');
-	is($ibx->{nntpserver}, 'news.example.com', 'global NNTP server');
+	is_deeply($ibx->nntp_url({ www => { pi_cfg => $cfg }}),
+		[ 'nntp://news.example.com/inbox.test' ],
+		'nntp_url uses global NNTP server');
 
 	$str = <<EOF;
 $pfx.address=test\@example.com
 $pfx.inboxdir=/path/to/non/existent
+$pfx.newsgroup=inbox.test
 $pfx.nntpserver=news.alt.example.com
+publicinbox.nntpserver=news.example.com
 EOF
 	$cfg = PublicInbox::Config->new(\$str);
 	$ibx = $cfg->lookup_name('test');
-	is($ibx->{nntpserver}, 'news.alt.example.com','per-inbox NNTP server');
+	is_deeply($ibx->nntp_url({ www => { pi_cfg => $cfg }}),
+		[ 'nntp://news.alt.example.com/inbox.test' ],
+		'nntp_url uses per-inbox NNTP server');
 }
 
 # no obfuscate domains

  reply	other threads:[~2021-09-16  0:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-16  0:26 [PATCH 0/3] www: support publicinbox.imapserver Eric Wong
2021-09-16  0:26 ` Eric Wong [this message]
2021-09-16  0:26 ` [PATCH 2/3] " Eric Wong
2021-09-16  0:26 ` [PATCH 3/3] www_stream: note existence of IMAP and NNTP URLs Eric Wong

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=20210916002653.12188-2-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).