[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Rsslib: Cache internal feeds using cachelib instead of the database, and...
Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a0226ad6d9b6_38190dac52360@gitlab-sidekiq-low-urgency-cpu-bound-v2-f4577dd4d-bdppk.mail> |
Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
391abe5c by Merci Jacob at 2026-05-11T18:39:40+00:00
[ENH] Rsslib: Cache internal feeds using cachelib instead of the database, and include a TTL element in the output
---
* remove `tiki_rss_feeds` table
* [ENH] Rsslib: Cache internal feeds using cachelib instead of the database, and include a TTL element in the output
See merge request tikiwiki/tiki!10046
- - - - -
22 changed files:
- db/tiki.sql
- db/tiki_convert_myisam_to_innodb.sql
- doc/devtools/sharetiki.sh
- doc/devtools/sharetikidev.sh
- + installer/schema/20260418_drop_rss_feeds_table_tiki.sql
- lib/prefs/feed.php
- lib/rss/rsslib.php
- templates/admin/include_rss.tpl
- tiki-articles_rss.php
- tiki-blog_rss.php
- tiki-blogs_rss.php
- tiki-calendars_rss.php
- tiki-directories_rss.php
- tiki-directory_rss.php
- tiki-file_galleries_rss.php
- tiki-file_gallery_rss.php
- tiki-forum_rss.php
- tiki-forums_rss.php
- tiki-shoutbox_rss.php
- tiki-tracker_rss.php
- tiki-wiki_rss.php
- tiki-wiki_rss_no_diff.php
Changes:
=====================================
db/tiki.sql
=====================================
@@ -2200,16 +2200,6 @@ CREATE TABLE `tiki_rss_modules` (
KEY `name` (name)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
-DROP TABLE IF EXISTS `tiki_rss_feeds`;
-CREATE TABLE `tiki_rss_feeds` (
- `name` varchar(60) NOT NULL default '',
- `rssVer` char(1) NOT NULL default '1',
- `refresh` int(8) default '300',
- `lastUpdated` int(14) default NULL,
- `cache` longblob,
- PRIMARY KEY (`name`,`rssVer`)
-) ENGINE=MyISAM;
-
DROP TABLE IF EXISTS `tiki_search_stats`;
CREATE TABLE `tiki_search_stats` (
`term` varchar(50) NOT NULL default '',
=====================================
db/tiki_convert_myisam_to_innodb.sql
=====================================
@@ -164,7 +164,6 @@ ALTER TABLE `tiki_received_pages` ENGINE=InnoDB;
ALTER TABLE `tiki_referer_stats` ENGINE=InnoDB;
ALTER TABLE `tiki_registration_fields` ENGINE=InnoDB;
ALTER TABLE `tiki_related_categories` ENGINE=InnoDB;
-ALTER TABLE `tiki_rss_feeds` ENGINE=InnoDB;
ALTER TABLE `tiki_rss_items` ENGINE=InnoDB;
ALTER TABLE `tiki_rss_modules` ENGINE=InnoDB;
ALTER TABLE `tiki_schema` ENGINE=InnoDB;
=====================================
doc/devtools/sharetiki.sh
=====================================
@@ -57,7 +57,6 @@ mysqldump -e -f --add-drop-table -h"$RDBHOST" -u"$RDBUSER" -p"$RDBPASS" "$RDBNAM
tiki_pages \
tiki_quicktags \
tiki_related_categories \
- tiki_rss_feeds \
tiki_rss_modules \
tiki_structures \
tiki_topics \
=====================================
doc/devtools/sharetikidev.sh
=====================================
@@ -47,7 +47,6 @@ mysqldump -e -f --add-drop-table -h"$RDBHOST" -u"$RDBUSER" -p"$RDBPASS" "$RDBNAM
tiki_pages \
tiki_quicktags \
tiki_related_categories \
- tiki_rss_feeds \
tiki_rss_modules \
tiki_structures \
tiki_wiki_attachments \
=====================================
installer/schema/20260418_drop_rss_feeds_table_tiki.sql
=====================================
@@ -0,0 +1 @@
+DROP TABLE `tiki_rss_feeds`;
\ No newline at end of file
=====================================
lib/prefs/feed.php
=====================================
@@ -92,6 +92,16 @@ function prefs_feed_list()
'default' => '300', // 5 minutes
'detail' => tra('Feed caching is done for anonymous users only.'),
],
+ 'feed_ttl' => [
+ 'name' => tra('Feed TTL'),
+ 'description' => tra('Time to live for the feed in minutes.'),
+ 'type' => 'text',
+ 'size' => '5',
+ 'filter' => 'digits',
+ 'units' => tra('minutes'),
+ 'hint' => tra('Time to live is an optional sub-element of <channel> that specifies the number of minutes that indicates how long a channel can be cached before refreshing from the source.'),
+ 'default' => '30',
+ ],
'feed_articles' => [
'name' => tra('RSS for articles'),
'description' => tra('RSS feeds for articles'),
=====================================
lib/rss/rsslib.php
=====================================
@@ -36,7 +36,6 @@ class RSSLib extends TikiDb_Bridge
{
self::$cachelib = $cachelib ?? TikiLib::lib('cache');
$this->items = $this->table('tiki_rss_items');
- $this->feeds = $this->table('tiki_rss_feeds');
$this->modules = $this->table('tiki_rss_modules');
}
@@ -103,77 +102,52 @@ class RSSLib extends TikiDb_Bridge
return $ver;
}
- /* check for cached rss feed data */
- public function get_from_cache($uniqueid)
- {
- global $tikilib, $user, $prefs;
-
- $rss_version = $this->get_current_feed_format();
-
- $output = [];
- $output["content-type"] = "application/xml";
- $output["encoding"] = "UTF-8";
- $output["data"] = "EMPTY";
+ public function cacheGeneratedFeed($uniqueId, $data)
+ {
+ global $user, $tikilib;
// caching rss data for anonymous users only
- if (isset($user) && $user <> "") {
- return $output;
+ if (isset($user) && $user != "") {
+ return;
}
- $res = $this->feeds->fetchFullRow(['name' => $uniqueid, 'rssVer' => $rss_version]);
- if (! $res) {
- // nothing found, then insert empty row for this feed+rss_ver
- $this->feeds->insert(
- [
- 'name' => $uniqueid,
- 'rssVer' => $rss_version,
- 'refresh' => (int) $prefs['feed_cache_time'],
- 'lastUpdated' => self::EMPTY_CACHE_UPDATED_AT,
- 'cache' => '-',
- ]
- );
- } else {
- // entry found in db:
- $output["data"] = $res["cache"];
- // $refresh = $res["refresh"]; // global cache time currently
- $refresh = $this->cacheLifetime($prefs['feed_cache_time'], TimeUnit::SECONDS); // global cache time currently
- $lastUpdated = $res["lastUpdated"];
- // up to date? if not, then set trigger to reload data:
- if ($tikilib->now - $lastUpdated >= $refresh) {
- $output["data"] = "EMPTY";
- }
+ if (empty($data) || $data == "EMPTY") {
+ return;
}
- $output['content-type'] = 'application/xml';
- return $output;
+
+ self::$cachelib->cacheItem($uniqueId, serialize([
+ 'data' => $data,
+ 'lastUpdated' => $tikilib->now,
+ ]));
}
- /* put to cache */
- public function put_to_cache($uniqueid, $rss_version, $output)
+ public function getGeneratedFeedFromCache($uniqueId)
{
- global $user, $tikilib;
+ global $tikilib, $prefs, $user;
+
+ $output = [
+ 'content-type' => 'application/xml',
+ 'encoding' => 'UTF-8',
+ 'data' => 'EMPTY',
+ ];
+
// caching rss data for anonymous users only
- if (isset($user) && $user <> "") {
- return;
- }
- if ($output == "" || $output == "EMPTY") {
- return;
+ if (isset($user) && $user != "") {
+ return $output;
}
- $rss_version = $rss_version ?? $this->get_current_feed_format();
-
- // update cache with new generated data if data not empty
+ $cacheData = self::$cachelib->getSerialized($uniqueId);
+ if ($cacheData) {
+ $refresh = $this->cacheLifetime($prefs['feed_cache_time'], TimeUnit::SECONDS);
+ if ($tikilib->now - $cacheData['lastUpdated'] < $refresh) {
+ $output['data'] = $cacheData['data'];
+ } else {
+ self::$cachelib->invalidate($uniqueId);
+ }
+ }
- $this->feeds->update(
- [
- 'cache' => $output,
- 'lastUpdated' => $tikilib->now,
- ],
- [
- 'name' => $uniqueid,
- 'rssVer' => $rss_version,
- ]
- );
+ return $output;
}
/**
@@ -212,7 +186,6 @@ class RSSLib extends TikiDb_Bridge
Feedback::errorAndDie($msg, \Laminas\Http\Response::STATUS_CODE_409);
}
- $feed_format = $this->get_current_feed_format();
$feed_format_name = $this->get_current_feed_format_name();
if ($prefs['feed_cache_time'] < 1) {
@@ -221,7 +194,7 @@ class RSSLib extends TikiDb_Bridge
// only get cache data if rss cache is enabled
if ($fromcache) {
- $output = $this->get_from_cache($uniqueid, $feed_format);
+ $output = $this->getGeneratedFeedFromCache($uniqueid);
if ($output['data'] != 'EMPTY') {
return $output;
}
@@ -334,7 +307,12 @@ class RSSLib extends TikiDb_Bridge
}
$data = $feed->export($feed_format_name);
- $this->put_to_cache($uniqueid, $feed_format, $data);
+
+ if ($feed_format_name == 'rss') {
+ $data = $this->addTTLToGeneratedFeed($data);
+ }
+
+ $this->cacheGeneratedFeed($uniqueid, $data);
$output = [];
$output["data"] = $data;
@@ -1119,6 +1097,27 @@ class RSSLib extends TikiDb_Bridge
return self::DEFAULT_FEED_TTL;
}
+ private function addTTLToGeneratedFeed($feedData): string
+ {
+ global $prefs;
+
+ if ((int) $prefs['feed_ttl'] <= self::DEFAULT_FEED_TTL) {
+ return $feedData;
+ }
+
+ $DOM = new DOMDocument();
+ $DOM->loadXML($feedData);
+ $xpath = new DOMXPath($DOM);
+
+ $channelNodes = $xpath->query('//*[local-name()="channel"]');
+ if ($channelNodes->length > 0) {
+ $ttlElement = $DOM->createElement('ttl', $prefs['feed_ttl']);
+ $firstItem = $xpath->query('./*[local-name()="item"]', $channelNodes->item(0))->item(0);
+ $channelNodes->item(0)->insertBefore($ttlElement, $firstItem);
+ }
+ return $DOM->saveXML();
+ }
+
public function loadRss(array $params): array
{
global $tikilib;
=====================================
templates/admin/include_rss.tpl
=====================================
@@ -25,6 +25,7 @@
{preference name=feed_img}
{preference name=feed_language}
{preference name=feed_cache_time}
+ {preference name=feed_ttl}
{preference name=feed_basic_auth}
{/tab}
{tab name="{tr}Feeds{/tr}"}
=====================================
tiki-articles_rss.php
=====================================
@@ -93,7 +93,7 @@ if ($topic and ! $tikilib->user_has_perm_on_object($user, $topic, 'topic', 'tiki
require_once('tiki-rss_error.php');
}
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = $prefs['feed_articles_title'];
=====================================
tiki-blog_rss.php
=====================================
@@ -34,7 +34,7 @@ if ($tiki_p_read_blog != 'y') {
$feed = 'blog';
$id = 'blogId';
$uniqueid = "$feed.$id=" . $_REQUEST["$id"];
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output['data'] == 'EMPTY') {
$tmp = $bloglib->get_blog($_REQUEST["$id"]);
=====================================
tiki-blogs_rss.php
=====================================
@@ -34,7 +34,7 @@ if ($res) {
}
$feed = "blogs";
$uniqueid = $feed;
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = $prefs['feed_blogs_title'];
$desc = $prefs['feed_blogs_desc'];
=====================================
tiki-calendars_rss.php
=====================================
@@ -35,7 +35,7 @@ if (isset($_REQUEST["calendarIds"])) {
} else {
$uniqueid = $feed;
}
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = $prefs['feed_' . $feed . '_title'];
=====================================
tiki-directories_rss.php
=====================================
@@ -34,7 +34,7 @@ if ($res) {
}
$feed = "directories";
$uniqueid = $feed;
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = $prefs['feed_directories_title'];
$desc = $prefs['feed_directories_desc'];
=====================================
tiki-directory_rss.php
=====================================
@@ -30,7 +30,7 @@ if (! isset($_REQUEST["parent"])) {
}
$feed = "directory";
$uniqueid = $feed . "?parent=" . $_REQUEST["parent"];
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = tra("Tiki RSS feed for directory sites");
$rc = $dirlib->dir_get_category($_REQUEST["parent"]);
=====================================
tiki-file_galleries_rss.php
=====================================
@@ -22,7 +22,7 @@ $filegallib = TikiLib::lib('filegal');
$feed = "filegals";
$uniqueid = $feed;
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = $prefs['feed_file_galleries_title'];
=====================================
tiki-file_gallery_rss.php
=====================================
@@ -43,7 +43,7 @@ if (empty($galleryIds)) {
$feed = 'filegal';
$uniqueid = "$feed.id=" . md5(implode('_', $galleryIds));
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$filegallib = TikiLib::lib('filegal');
=====================================
tiki-forum_rss.php
=====================================
@@ -41,7 +41,7 @@ $commentslib = TikiLib::lib('comments');
$feed = "forum";
$id = "forumId";
$uniqueid = "$feed.$id=" . $_REQUEST["$id"];
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$tmp = $commentslib->get_forum($_REQUEST["forumId"]);
=====================================
tiki-forums_rss.php
=====================================
@@ -30,7 +30,7 @@ if ($res) {
$feed = "forums";
$uniqueid = $feed;
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = $prefs['feed_forums_title'];
=====================================
tiki-shoutbox_rss.php
=====================================
@@ -31,7 +31,7 @@ if ($res) {
$feed = "shoutbox";
$uniqueid = $feed;
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = $prefs['feed_shoutbox_title'];
$desc = $prefs['feed_shoutbox_desc'];
=====================================
tiki-tracker_rss.php
=====================================
@@ -39,7 +39,7 @@ if (isset($_REQUEST['sort_mode'])) {
} else {
$sort_mode = 'created_desc';
}
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$tmp = $trklib->get_tracker($_REQUEST["$id"]);
if (empty($tmp)) {
=====================================
tiki-wiki_rss.php
=====================================
@@ -35,7 +35,7 @@ if ($res) {
$feed = "wiki";
$uniqueid = $feed;
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = $prefs['feed_wiki_title'];
=====================================
tiki-wiki_rss_no_diff.php
=====================================
@@ -33,7 +33,7 @@ if ($res) {
$feed = "wiki";
$uniqueid = $feed;
-$output = $rsslib->get_from_cache($uniqueid);
+$output = $rsslib->getGeneratedFeedFromCache($uniqueid);
if ($output["data"] == "EMPTY") {
$title = $prefs['feed_wiki_title'];
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/391abe5c8ba5c214a6fe0b3c9443e26398eec752
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/391abe5c8ba5c214a6fe0b3c9443e26398eec752
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs