about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-12-17 04:27:52 +0000
committerEric Wong <e@80x24.org>2016-12-17 05:41:49 +0000
commitf084e94a4774b95eb45f55fc9f0dfda678522e54 (patch)
tree9606587e01b4e57b650d1f805b5046611110fbb3 /lib
parent464048b28be5063a3151742feaaa170c9d9e3b19 (diff)
downloadpublic-inbox-f084e94a4774b95eb45f55fc9f0dfda678522e54.tar.gz
feed: support publicinbox.<name>.feedmax
This allows users to customize by using smaller or larger Atom
feeds than the default value of 25 entries.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Config.pm3
-rw-r--r--lib/PublicInbox/Feed.pm5
-rw-r--r--lib/PublicInbox/Inbox.pm11
3 files changed, 14 insertions, 5 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 8d66cf8c..6e31df72 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -145,7 +145,8 @@ sub _fill {
         my $rv = {};
 
         foreach my $k (qw(mainrepo address filter url newsgroup
-                        infourl watch watchheader httpbackendmax)) {
+                        infourl watch watchheader httpbackendmax
+                        feedmax)) {
                 my $v = $self->{"$pfx.$k"};
                 $rv->{$k} = $v if defined $v;
         }
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 31d82adb..2a33fd29 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -8,9 +8,6 @@ use warnings;
 use Email::MIME;
 use PublicInbox::View;
 use PublicInbox::WwwAtomStream;
-use constant {
-        MAX_PER_PAGE => 25, # this needs to be tunable
-};
 
 # main function
 sub generate {
@@ -114,7 +111,7 @@ sub new_html_footer {
 
 sub each_recent_blob {
         my ($ctx, $cb) = @_;
-        my $max = $ctx->{max} || MAX_PER_PAGE;
+        my $max = $ctx->{-inbox}->{feedmax};
         my $hex = '[a-f0-9]';
         my $addmsg = qr!^:000000 100644 \S+ \S+ A\t(${hex}{2}/${hex}{38})$!;
         my $delmsg = qr!^:100644 000000 \S+ \S+ D\t(${hex}{2}/${hex}{38})$!;
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 8c639082..5503980f 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -29,11 +29,22 @@ sub _weaken_later ($) {
         $WEAKEN->{"$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\d+\z/;
+        }
+        $opts->{$field} = $val || $default;
+}
+
 sub new {
         my ($class, $opts) = @_;
         my $v = $opts->{address} ||= 'public-inbox@example.com';
         my $p = $opts->{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v;
         $opts->{domain} = ($p =~ /\@(\S+)\z/) ? $1 : 'localhost';
+        _set_uint($opts, 'feedmax', 25);
         weaken($opts->{-pi_config});
         bless $opts, $class;
 }