From 168cf351e29c71209b0f1ade9bed522c9c1bc57f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 6 Mar 2015 14:14:51 +0300 Subject: [PATCH] add housekeeping task for orphaned counter cache entries --- include/ccache.php | 1 + include/rssfuncs.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/ccache.php b/include/ccache.php index 406dec81..b938b866 100644 --- a/include/ccache.php +++ b/include/ccache.php @@ -139,6 +139,7 @@ $result = db_query("SELECT SUM(value) AS sv FROM ttrss_counters_cache, ttrss_feeds WHERE id = feed_id AND $cat_qpart AND + ttrss_counters_cache.owner_uid = $owner_uid AND ttrss_feeds.owner_uid = '$owner_uid'"); $unread = (int) db_fetch_result($result, 0, "sv"); diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 1a26e048..a27a9174 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -1393,6 +1393,24 @@ return $error; } */ + function cleanup_counters_cache($debug) { + $result = db_query("DELETE FROM ttrss_counters_cache + WHERE feed_id > 0 AND + (SELECT COUNT(id) FROM ttrss_feeds WHERE + id = feed_id AND + ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid) = 0"); + $frows = db_affected_rows($result); + + $result = db_query("DELETE FROM ttrss_cat_counters_cache + WHERE feed_id > 0 AND + (SELECT COUNT(id) FROM ttrss_feed_categories WHERE + id = feed_id AND + ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid) = 0"); + $crows = db_affected_rows($result); + + _debug("Removed $frows (feeds) $crows (cats) orphaned counter cache entries."); + } + function housekeeping_common($debug) { expire_cached_files($debug); expire_lock_files($debug); @@ -1402,6 +1420,7 @@ _debug("Feedbrowser updated, $count feeds processed."); purge_orphans( true); + cleanup_counters_cache($debug); $rc = cleanup_tags( 14, 50000); _debug("Cleaned $rc cached tags."); -- 2.39.5