]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
config: handle limiter `max' knob in ->setup_limiter
authorEric Wong <e@80x24.org>
Sat, 8 Feb 2025 03:26:39 +0000 (03:26 +0000)
committerEric Wong <e@80x24.org>
Tue, 11 Feb 2025 00:11:43 +0000 (00:11 +0000)
Handling all config knobs in the same sub is more logical and
reduces the size of the frequently-loaded PublicInbox::Config
package.

lib/PublicInbox/Config.pm
lib/PublicInbox/Limiter.pm

index 4045d6d36b00664434eb4e5a236972e2e8b33206..6ff1678347a66fc7b3101dfa06e28000bbd3d46a 100644 (file)
@@ -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;
        };
index 49981e21b589f2d18ec514e283b05f5cebfeae26..fc62d0d40b7948f39026db0b97b0ba7142faca36 100644 (file)
@@ -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 <<EOM
+W: `$k=$v' is not a positive integer in $cfg->{-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 <<EOM;
+W: could not parse `$k=$v' in $cfg->{-f} (ignored)
+EOM
                        next;
                }
                my $inf = $v =~ /\binfinity\b/i ?