summaryrefslogtreecommitdiff
path: root/lib/VNWeb/Misc
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-09-17 11:38:16 +0200
committerYorhel <git@yorhel.nl>2020-09-17 11:41:43 +0200
commit266d9e9b9f4fd3f840f950aefe7e82ecbc0f1689 (patch)
tree960b83064d2ae5aada9c091dde2c13c5526a82b8 /lib/VNWeb/Misc
parent62f6803b581d174db4f7259c7dcfcca19730fc89 (diff)
Feeds: Move feed generation form Multi to VNWeb
This means the feeds are now generated on demand rather than every 15 minutes. Main reason for originally implementing this into Multi was because RSS feeds tended to get requested a *lot* and I didn't want those requests to impact site performance, but now that RSS is almost dead it doesn't really matter that much anymore. A caching layer can still be added anyway. Be sure to restart Multi and delete www/feeds/ after this change.
Diffstat (limited to 'lib/VNWeb/Misc')
-rw-r--r--lib/VNWeb/Misc/Feeds.pm78
-rw-r--r--lib/VNWeb/Misc/History.pm2
-rw-r--r--lib/VNWeb/Misc/HomePage.pm1
3 files changed, 79 insertions, 2 deletions
diff --git a/lib/VNWeb/Misc/Feeds.pm b/lib/VNWeb/Misc/Feeds.pm
new file mode 100644
index 00000000..6d3a3eba
--- /dev/null
+++ b/lib/VNWeb/Misc/Feeds.pm
@@ -0,0 +1,78 @@
+package VNWeb::Misc::Feeds;
+
+use VNWeb::Prelude;
+use TUWF::XML ':xml';
+
+
+sub datetime { strftime '%Y-%m-%dT%H:%M:%SZ', gmtime shift }
+
+
+sub feed {
+ my($path, $title, $data) = @_;
+ my $base = tuwf->reqBaseURI();
+
+ xml;
+ tag feed => xmlns => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en', 'xml:base' => "$base/", sub {
+ tag title => $title;
+ tag updated => datetime max grep $_, map +($_->{published}, $_->{updated}), @$data;
+ tag id => $base.$path;
+ tag link => rel => 'self', type => 'application/atom+xml', href => $base.tuwf->reqPath(), undef;
+ tag link => rel => 'alternate', type => 'text/html', href => $base.$path, undef;
+
+ tag entry => sub {
+ tag id => "$base/$_->{id}";
+ tag title => $_->{title};
+ tag updated => datetime($_->{updated} || $_->{published});
+ tag published => datetime $_->{published} if $_->{published};
+ tag author => sub {
+ tag name => $_->{user_name};
+ tag uri => "$base/u$_->{user_id}";
+ } if $_->{user_id};
+ tag link => rel => 'alternate', type => 'text/html', href => "$base/$_->{id}", undef;
+ tag summary => type => 'html', bb_format $_->{summary}, maxlength => 300 if $_->{summary};
+ } for @$data;
+ }
+}
+
+
+TUWF::get qr{/feeds/announcements.atom}, sub {
+ feed '/t/an', 'VNDB Site Announcements', tuwf->dbAlli('
+ SELECT t.id, t.title, tp.msg AS summary
+ , ', sql_totime('tp.date'), 'AS published,', sql_totime('tp.edited'), 'AS updated,', sql_user(), '
+ FROM threads t
+ JOIN threads_posts tp ON tp.tid = t.id AND tp.num = 1
+ JOIN threads_boards tb ON tb.tid = t.id AND tb.type = \'an\'
+ LEFT JOIN users u ON u.id = tp.uid
+ WHERE NOT t.hidden AND NOT t.private
+ ORDER BY tb.tid DESC
+ LIMIT 10'
+ );
+};
+
+
+TUWF::get qr{/feeds/changes.atom}, sub {
+ my($lst) = VNWeb::Misc::History::fetch(undef, undef, {m=>1,h=>1,p=>1}, {results=>25});
+ for (@$lst) {
+ $_->{id} = "$_->{type}$_->{itemid}.$_->{rev}";
+ $_->{summary} = $_->{comments};
+ $_->{updated} = $_->{added};
+ }
+ feed '/hist', 'VNDB Recent Changes', $lst;
+};
+
+
+TUWF::get qr{/feeds/posts.atom}, sub {
+ feed '/t', 'VNDB Recent Posts', tuwf->dbAlli('
+ SELECT t.id||\'.\'||tp.num AS id, t.title||\' (#\'||tp.num||\')\' AS title, tp.msg AS summary
+ , ', sql_totime('tp.date'), 'AS published,', sql_totime('tp.edited'), 'AS updated,', sql_user(), '
+ FROM threads_posts tp
+ JOIN threads t ON t.id = tp.tid
+ LEFT JOIN users u ON u.id = tp.uid
+ WHERE NOT tp.hidden AND NOT t.hidden AND NOT t.private
+ ORDER BY tp.date DESC
+ LIMIT ', \25
+ );
+};
+
+
+1;
diff --git a/lib/VNWeb/Misc/History.pm b/lib/VNWeb/Misc/History.pm
index 691d035a..dcddfb4b 100644
--- a/lib/VNWeb/Misc/History.pm
+++ b/lib/VNWeb/Misc/History.pm
@@ -3,7 +3,7 @@ package VNWeb::Misc::History;
use VNWeb::Prelude;
-# Also used by Misc::HomePage
+# Also used by Misc::HomePage and Misc::Feeds
sub fetch {
my($type, $id, $filt, $opt) = @_;
diff --git a/lib/VNWeb/Misc/HomePage.pm b/lib/VNWeb/Misc/HomePage.pm
index 612cfa04..f71d776b 100644
--- a/lib/VNWeb/Misc/HomePage.pm
+++ b/lib/VNWeb/Misc/HomePage.pm
@@ -3,7 +3,6 @@ package VNWeb::Misc::HomePage;
use VNWeb::Prelude;
use VNWeb::Filters;
use VNWeb::Discussions::Lib 'enrich_boards';
-use POSIX 'strftime';
sub screens_ {