unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] PublicInbox::Feed owns `feedmax' default value
Date: Fri, 11 Dec 2020 20:49:58 +0000	[thread overview]
Message-ID: <20201211204958.23794-1-e@80x24.org> (raw)

There's no need to have extra code in the Inbox package for this
or to waste dozens of bytes for every Inbox object which uses
the default value.

This makes our code more flexible w.r.t Inbox-like ExtSearch
objects and fixes uninitialized value warnings with ->ALL.
---
 lib/PublicInbox/Feed.pm  |  2 +-
 lib/PublicInbox/Inbox.pm | 17 ++++++-----------
 t/config.t               |  2 --
 3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 4dd584d3..f570a25d 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -80,7 +80,7 @@ sub _no_thread () {
 sub recent_msgs {
 	my ($ctx) = @_;
 	my $ibx = $ctx->{ibx};
-	my $max = $ibx->{feedmax};
+	my $max = $ibx->{feedmax} // 25;
 	return PublicInbox::View::paginate_recent($ctx, $max) if $ibx->over;
 
 	# only for rare v1 inboxes which aren't indexed at all
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 586bd561..4e3c23f3 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -74,16 +74,6 @@ sub _cleanup_later ($) {
 	$CLEANUP->{"$self"} = $self;
 }
 
-sub _set_uint ($$$) {
-	my ($opts, $field, $default) = @_;
-	my $val = $opts->{$field};
-	if (defined $val) {
-		$val = $val->[-1] if ref($val) eq 'ARRAY';
-		$val = undef if $val !~ /\A[0-9]+\z/;
-	}
-	$opts->{$field} = $val || $default;
-}
-
 sub _set_limiter ($$$) {
 	my ($self, $pi_cfg, $pfx) = @_;
 	my $lkey = "-${pfx}_limiter";
@@ -112,7 +102,12 @@ sub new {
 	$opts->{domain} = ($p =~ /\@(\S+)\z/) ? $1 : 'localhost';
 	my $pi_cfg = delete $opts->{-pi_cfg};
 	_set_limiter($opts, $pi_cfg, 'httpbackend');
-	_set_uint($opts, 'feedmax', 25);
+	my $fmax = $opts->{feedmax};
+	if (defined($fmax) && $fmax =~ /\A[0-9]+\z/) {
+		$opts->{feedmax} += 0;
+	} else {
+		delete $opts->{feedmax};
+	}
 	$opts->{nntpserver} ||= $pi_cfg->{'publicinbox.nntpserver'};
 	my $dir = $opts->{inboxdir};
 	if (defined $dir && -f "$dir/inbox.lock") {
diff --git a/t/config.t b/t/config.t
index ee51c6cc..99a7fef4 100644
--- a/t/config.t
+++ b/t/config.t
@@ -41,7 +41,6 @@ my ($tmpdir, $for_destroy) = tmpdir();
 		'url' => [ 'http://example.com/meta' ],
 		-primary_address => 'meta@public-inbox.org',
 		'name' => 'meta',
-		feedmax => 25,
 		-httpbackend_limiter => undef,
 		nntpserver => undef,
 	}, "lookup matches expected output");
@@ -58,7 +57,6 @@ my ($tmpdir, $for_destroy) = tmpdir();
 		'inboxdir' => '/home/pi/test-main.git',
 		'domain' => 'public-inbox.org',
 		'name' => 'test',
-		feedmax => 25,
 		'url' => [ 'http://example.com/test' ],
 		-httpbackend_limiter => undef,
 		nntpserver => undef,

                 reply	other threads:[~2020-12-11 20:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201211204958.23794-1-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.
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).