]> git.wh0rd.org Git - tt-rss.git/commitdiff
add housekeeping task for orphaned counter cache entries
authorAndrew Dolgov <noreply@fakecake.org>
Fri, 6 Mar 2015 11:14:51 +0000 (14:14 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Fri, 6 Mar 2015 11:14:51 +0000 (14:14 +0300)
include/ccache.php
include/rssfuncs.php

index 406dec81d1b1da8e0e88feadaff697270f884bc6..b938b86643ad17935a734453f1f2edf8c8b1bd1e 100644 (file)
                        $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");
index 1a26e0485a3dac320df9fed0fd533d6681ab513e..a27a91747a1ec91559805f35ad48207e1ea28597 100644 (file)
                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);
                _debug("Feedbrowser updated, $count feeds processed.");
 
                purge_orphans( true);
+               cleanup_counters_cache($debug);
                $rc = cleanup_tags( 14, 50000);
 
                _debug("Cleaned $rc cached tags.");