]> Sergey Matveev's repositories - public-inbox.git/commitdiff
feed: support publicinbox.<name>.feedmax
authorEric Wong <e@80x24.org>
Sat, 17 Dec 2016 04:27:52 +0000 (04:27 +0000)
committerEric Wong <e@80x24.org>
Sat, 17 Dec 2016 05:41:49 +0000 (05:41 +0000)
This allows users to customize by using smaller or larger Atom
feeds than the default value of 25 entries.

Documentation/public-inbox-config.pod
lib/PublicInbox/Config.pm
lib/PublicInbox/Feed.pm
lib/PublicInbox/Inbox.pm
t/config.t
t/feed.t

index 0037645734f65bee94cc4b195424f08453e5e837..cfd6c93d1dbaa51c0dc7bb98e21cf33dcd119a24 100644 (file)
@@ -120,6 +120,14 @@ addresses or mirrors.
 
 Default: none
 
+=item publicinbox.<name>.feedmax
+
+The size of an Atom feed for the inbox.  If specified more than
+once, only the last value is used.  Invalid values (<= 0) will
+be treated as the default value.
+
+Default: 25
+
 =back
 
 =head1 ENVIRONMENT
index 8d66cf8c35fcb9aba02aaed2286e5e4da580234c..6e31df7267fe0c64be3c8dc95db8e8f66819a9df 100644 (file)
@@ -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;
        }
index 31d82adbb634d478e2354e43348ebda1401ed429..2a33fd291eebf305be595026a365fefcf5bbaa64 100644 (file)
@@ -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})$!;
index 8c639082a4189f6ad91cb3e0ec3a2e9612bc41d2..5503980fc0ca3d297d6062709b3dfacb44aae800 100644 (file)
@@ -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;
 }
index 073d1d03074db83d6054e11991910ccee7d1b66d..4bbbc83897613847c5c467ee6bf4fafe9f1d8398 100644 (file)
@@ -30,6 +30,7 @@ my $tmpdir = tempdir('pi-config-XXXXXX', TMPDIR => 1, CLEANUP => 1);
                'url' => 'http://example.com/meta',
                -primary_address => 'meta@public-inbox.org',
                'name' => 'meta',
+               feedmax => 100,
                -pi_config => $cfg,
        }, "lookup matches expected output");
 
@@ -45,6 +46,7 @@ my $tmpdir = tempdir('pi-config-XXXXXX', TMPDIR => 1, CLEANUP => 1);
                'mainrepo' => '/home/pi/test-main.git',
                'domain' => 'public-inbox.org',
                'name' => 'test',
+               feedmax => 100,
                'url' => 'http://example.com/test',
                -pi_config => $cfg,
        }, "lookup matches expected output for test");
index 19a9ba09b4149343edd8879bc340ae532bb2cc51..b60273ed53b313112f9ad175659a2936c3c454dd 100644 (file)
--- a/t/feed.t
+++ b/t/feed.t
@@ -46,6 +46,7 @@ my $ibx = PublicInbox::Inbox->new({
        name => 'testbox',
        mainrepo => $git_dir,
        url => 'http://example.com/test',
+       feedmax => 3,
 });
 my $git = $ibx->git;
 my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
@@ -101,10 +102,7 @@ EOF
 {
        # check initial feed
        {
-               my $feed = string_feed({
-                       -inbox => $ibx,
-                       max => 3
-               });
+               my $feed = string_feed({ -inbox => $ibx });
                SKIP: {
                        skip 'XML::Feed missing', 2 unless $have_xml_feed;
                        my $p = XML::Feed->parse(\$feed);
@@ -142,10 +140,7 @@ EOF
 
        # check spam shows up
        {
-               my $spammy_feed = string_feed({
-                       -inbox => $ibx,
-                       max => 3
-               });
+               my $spammy_feed = string_feed({ -inbox => $ibx });
                SKIP: {
                        skip 'XML::Feed missing', 2 unless $have_xml_feed;
                        my $p = XML::Feed->parse(\$spammy_feed);
@@ -167,7 +162,7 @@ EOF
 
        # spam no longer shows up
        {
-               my $feed = string_feed({ -inbox => $ibx, max => 3 });
+               my $feed = string_feed({ -inbox => $ibx });
                SKIP: {
                        skip 'XML::Feed missing', 2 unless $have_xml_feed;
                        my $p = XML::Feed->parse(\$feed);