Refactor post fetching in rss.cgi
DOC
}
+sub fetch_records {
+ my @out;
+ local $_;
+
+ foreach (@_) {
+ my $b = Blerg::Database->open_existing($_->{author});
+ my $data = $b->fetch($_->{record});
+ if (!defined $data) {
+ $b->close;
+ next;
+ }
+ my $timestamp = $b->timestamp($_->{record});
+ $b->close;
+ push @out, {
+ author => $_->{author},
+ record => $_->{record},
+ data => $data,
+ timestamp => $timestamp,
+ };
+ }
+
+ return @out;
+}
+
sub print_rss {
my ($type, $name, @items) = @_;
next REQUEST;
}
- my $bb = Blerg::Database->open_existing($username);
- my @list = $bb->subscription_list();
- $bb->close;
- @list = map {
- my $b = Blerg::Database->open_existing($_->{author});
- my $data = $b->fetch($_->{record});
- my $timestamp = $b->timestamp($_->{record});
- $b->close;
- {
- author => $_->{author},
- record => $_->{record},
- data => $data,
- timestamp => $timestamp,
- };
- } @list;
+ my $b = Blerg::Database->open_existing($username);
+ my @list = fetch_records($b->subscription_list());
+ $b->close;
print header(-type => 'application/rss+xml');
print_rss(feed => $username, @list);
# And present the content in case their client is broken
my $i = {
record => '?failed_redirect',
- timestamp => time,
+ timestamp => time,
data => qq{Your RSS aggregator is dumb and isn't following 301 redirects. Please manually redirect it here: ${baseurl}rss/user/$username}
};
print_rss(user => $username, $i);
$atag = '@' . $tag;
}
- my @list = Blerg::Database::tag_list($atag, 0, -1);
- @list = map {
- my $b = Blerg::Database->open_existing($_->{author});
- my $data = $b->fetch($_->{record});
- my $timestamp = $b->timestamp($_->{record});
- $b->close;
- {
- author => $_->{author},
- record => $_->{record},
- data => $data,
- timestamp => $timestamp,
- };
- } @list;
+ my @list = fetch_records(Blerg::Database::tag_list($atag, 0, -1));
print header(-type => 'application/rss+xml');
print_rss($path[0] => $atag, @list);