From 38e01270d876cc7e43923629f038bbae629f307b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 6 Mar 2019 19:06:05 +0300 Subject: [PATCH] archived feeds: expire old entries (schema bump) --- classes/handler/public.php | 6 +----- classes/pref/feeds.php | 4 ++-- classes/rpc.php | 4 ++-- classes/rssutils.php | 15 +++++++++++++++ include/functions.php | 2 +- schema/ttrss_schema_mysql.sql | 3 ++- schema/ttrss_schema_pgsql.sql | 3 ++- schema/versions/mysql/136.sql | 9 +++++++++ schema/versions/pgsql/136.sql | 9 +++++++++ 9 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 schema/versions/mysql/136.sql create mode 100644 schema/versions/pgsql/136.sql diff --git a/classes/handler/public.php b/classes/handler/public.php index 99c605dee..03c35f536 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -1137,10 +1137,8 @@ class Handler_Public extends Handler { print "

" . T_sprintf("Updating to schema version %d", SCHEMA_VERSION) . "

"; - print ""; - print_notice("Your Tiny Tiny RSS database is now updated to the latest version."); print "".__("Return to Tiny Tiny RSS").""; diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 6e0a68365..353775f4c 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1635,8 +1635,8 @@ class Pref_Feeds extends Handler_Protected { $new_feed_id = (int)$row['id'] + 1; $sth = $pdo->prepare("INSERT INTO ttrss_archived_feeds - (id, owner_uid, title, feed_url, site_url) - SELECT ?, owner_uid, title, feed_url, site_url from ttrss_feeds + (id, owner_uid, title, feed_url, site_url, created) + SELECT ?, owner_uid, title, feed_url, site_url, NOW() from ttrss_feeds WHERE id = ?"); $sth->execute([$new_feed_id, $id]); diff --git a/classes/rpc.php b/classes/rpc.php index 7220e10ea..76cca6f8e 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -240,8 +240,8 @@ class RPC extends Handler_Protected { $new_feed_id = (int)$row['id'] + 1; $sth = $this->pdo->prepare("INSERT INTO ttrss_archived_feeds - (id, owner_uid, title, feed_url, site_url) - SELECT ?, owner_uid, title, feed_url, site_url from ttrss_feeds + (id, owner_uid, title, feed_url, site_url, created) + SELECT ?, owner_uid, title, feed_url, site_url, NOW() from ttrss_feeds WHERE id = ?"); $sth->execute([$new_feed_id, $feed_id]); diff --git a/classes/rssutils.php b/classes/rssutils.php index 6048c8310..8684a2c5d 100755 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -1288,6 +1288,20 @@ class RSSUtils { } } + static function expire_feed_archive() { + Debug::log("Removing old archived feeds..."); + + $pdo = Db::pdo(); + + if (DB_TYPE == "pgsql") { + $pdo->query("DELETE FROM ttrss_archived_feeds + WHERE created < NOW() - INTERVAL '1 month'"); + } else { + $pdo->query("DELETE FROM ttrss_archived_feeds + WHERE created < DATE_SUB(NOW(), INTERVAL 1 MONTH)"); + } + } + static function expire_lock_files() { Debug::log("Removing old lock files...", Debug::$LOG_VERBOSE); @@ -1526,6 +1540,7 @@ class RSSUtils { RSSUtils::expire_cached_files(); RSSUtils::expire_lock_files(); RSSUtils::expire_error_log(); + RSSUtils::expire_feed_archive(); $count = RSSUtils::update_feedbrowser_cache(); Debug::log("Feedbrowser updated, $count feeds processed."); diff --git a/include/functions.php b/include/functions.php index d93be856d..2ab43e0b6 100755 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@