From: Eric Wong Date: Sat, 8 Feb 2025 03:26:39 +0000 (+0000) Subject: config: handle limiter `max' knob in ->setup_limiter X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d2a48e9e772e803cbdf02690d3c1023a81f2ed8;p=thirdparty%2Fpublic-inbox.git config: handle limiter `max' knob in ->setup_limiter Handling all config knobs in the same sub is more logical and reduces the size of the frequently-loaded PublicInbox::Config package. --- diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 4045d6d36..6ff167834 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -126,8 +126,7 @@ sub limiter { my ($self, $name, $max_default) = @_; $self->{-limiters}->{$name} //= do { require PublicInbox::Limiter; - my $n = $self->{"publicinboxlimiter.$name.max"}; - my $l = PublicInbox::Limiter->new($n || $max_default || 1); + my $l = PublicInbox::Limiter->new($max_default || 1); $l->setup_limiter($name, $self); $l; }; diff --git a/lib/PublicInbox/Limiter.pm b/lib/PublicInbox/Limiter.pm index 49981e21b..fc62d0d40 100644 --- a/lib/PublicInbox/Limiter.pm +++ b/lib/PublicInbox/Limiter.pm @@ -21,25 +21,29 @@ sub new { sub setup_limiter { my ($self, $name, $cfg) = @_; - my $k = "publicinboxlimiter.$name.depth"; - my $v = $cfg->{$k}; - if (defined $v) { + for my $f (qw(max depth)) { + my $k = "publicinboxlimiter.$name.$f"; + my $v = $cfg->{$k} // next; if ($v =~ /\A[1-9][0-9]*\z/) { - $self->{depth} = $v + 0; + $self->{$f} = $v + 0; } else { - warn "W: `$v' not a positive integer in $cfg->{-f}\n"; + warn <{-f} +EOM } } for my $rlim (@PublicInbox::Spawn::RLIMITS) { - $k = lc($rlim); + my $k = lc($rlim); $k =~ tr/_//d; $k = "publicinboxlimiter.$name.$k"; - $v = $cfg->{$k} // next; + my $v = $cfg->{$k} // next; my @rlimit = split(/\s*,\s*/, $v); if (scalar(@rlimit) == 1) { $rlimit[1] = $rlimit[0]; } elsif (scalar(@rlimit) != 2) { - warn "W: could not parse $k: $v (ignored)\n"; + warn <{-f} (ignored) +EOM next; } my $inf = $v =~ /\binfinity\b/i ?