From 6080cca9ca1de60a5d4a1ef06d4873eca07d9ef2 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 24 Jan 2020 14:25:31 +0300 Subject: [PATCH] scrap counter cache system; rework counters to sum() booleans instead --- classes/api.php | 10 -- classes/article.php | 73 ---------- classes/ccache.php | 211 ---------------------------- classes/counters.php | 303 ++++++++++++++++++++++------------------- classes/feeds.php | 24 +--- classes/pref/feeds.php | 14 +- classes/rssutils.php | 20 +-- include/functions.php | 17 --- 8 files changed, 170 insertions(+), 502 deletions(-) delete mode 100644 classes/ccache.php diff --git a/classes/api.php b/classes/api.php index 68c46d53c..339e9eef1 100755 --- a/classes/api.php +++ b/classes/api.php @@ -300,16 +300,6 @@ class API extends Handler { $num_updated = $sth->rowCount(); - if ($num_updated > 0 && $field == "unread") { - $sth = $this->pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries - WHERE ref_id IN ($article_qmarks)"); - $sth->execute($article_ids); - - while ($line = $sth->fetch()) { - CCache::update($line["feed_id"], $_SESSION["uid"]); - } - } - $this->wrap(self::STATUS_OK, array("status" => "OK", "updated" => $num_updated)); diff --git a/classes/article.php b/classes/article.php index fc81838ed..74dbdae53 100755 --- a/classes/article.php +++ b/classes/article.php @@ -27,69 +27,6 @@ class Article extends Handler_Protected { } } - /* - function view() { - $id = clean($_REQUEST["id"]); - $cids = explode(",", clean($_REQUEST["cids"])); - $mode = clean($_REQUEST["mode"]); - - // in prefetch mode we only output requested cids, main article - // just gets marked as read (it already exists in client cache) - - $articles = array(); - - if ($mode == "") { - array_push($articles, $this->format_article($id, false)); - } else if ($mode == "zoom") { - array_push($articles, $this->format_article($id, true, true)); - } else if ($mode == "raw") { - if (isset($_REQUEST['html'])) { - header("Content-Type: text/html"); - print ''; - } - - $article = $this->format_article($id, false, isset($_REQUEST["zoom"])); - print $article['content']; - return; - } - - $this->catchupArticleById($id, 0); - - if (!$_SESSION["bw_limit"]) { - foreach ($cids as $cid) { - if ($cid) { - array_push($articles, $this->format_article($cid, false, false)); - } - } - } - - print json_encode($articles); - } */ - - /* - private function catchupArticleById($id, $cmode) { - - if ($cmode == 0) { - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET - unread = false,last_read = NOW() - WHERE ref_id = ? AND owner_uid = ?"); - } else if ($cmode == 1) { - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET - unread = true - WHERE ref_id = ? AND owner_uid = ?"); - } else { - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET - unread = NOT unread,last_read = NOW() - WHERE ref_id = ? AND owner_uid = ?"); - } - - $sth->execute([$id, $_SESSION['uid']]); - - $feed_id = $this->getArticleFeed($id); - CCache::update($feed_id, $_SESSION["uid"]); - } - */ - static function create_published_article($title, $url, $content, $labels_str, $owner_uid) { @@ -718,16 +655,6 @@ class Article extends Handler_Protected { } $sth->execute(array_merge($ids, [$owner_uid])); - - /* update ccache */ - - $sth = $pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries - WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); - $sth->execute(array_merge($ids, [$owner_uid])); - - while ($line = $sth->fetch()) { - CCache::update($line["feed_id"], $owner_uid); - } } static function getLastArticleId() { diff --git a/classes/ccache.php b/classes/ccache.php deleted file mode 100644 index 2f19140e0..000000000 --- a/classes/ccache.php +++ /dev/null @@ -1,211 +0,0 @@ -prepare("UPDATE ttrss_counters_cache SET - value = 0 WHERE owner_uid = ?"); - $sth->execute([$owner_uid]); - - $sth = $pdo->prepare("UPDATE ttrss_cat_counters_cache SET - value = 0 WHERE owner_uid = ?"); - $sth->execute([$owner_uid]); - } - - static function remove($feed_id, $owner_uid, $is_cat = false) { - - $feed_id = (int) $feed_id; - - if (!$is_cat) { - $table = "ttrss_counters_cache"; - } else { - $table = "ttrss_cat_counters_cache"; - } - - $pdo = Db::pdo(); - - $sth = $pdo->prepare("DELETE FROM $table WHERE - feed_id = ? AND owner_uid = ?"); - $sth->execute([$feed_id, $owner_uid]); - - } - - static function update_all($owner_uid) { - - $pdo = Db::pdo(); - - if (get_pref('ENABLE_FEED_CATS', $owner_uid)) { - - $sth = $pdo->prepare("SELECT feed_id FROM ttrss_cat_counters_cache - WHERE feed_id > 0 AND owner_uid = ?"); - $sth->execute([$owner_uid]); - - while ($line = $sth->fetch()) { - CCache::update($line["feed_id"], $owner_uid, true); - } - - /* We have to manually include category 0 */ - - CCache::update(0, $owner_uid, true); - - } else { - $sth = $pdo->prepare("SELECT feed_id FROM ttrss_counters_cache - WHERE feed_id > 0 AND owner_uid = ?"); - $sth->execute([$owner_uid]); - - while ($line = $sth->fetch()) { - print CCache::update($line["feed_id"], $owner_uid); - - } - - } - } - - static function find($feed_id, $owner_uid, $is_cat = false, - $no_update = false) { - - // "" (null) is valid and should be cast to 0 (uncategorized) - // everything else i.e. tags are not - if (!is_numeric($feed_id) && $feed_id) - return; - - $feed_id = (int) $feed_id; - - if (!$is_cat) { - $table = "ttrss_counters_cache"; - } else { - $table = "ttrss_cat_counters_cache"; - } - - $pdo = Db::pdo(); - - $sth = $pdo->prepare("SELECT value FROM $table - WHERE owner_uid = ? AND feed_id = ? - LIMIT 1"); - - $sth->execute([$owner_uid, $feed_id]); - - if ($row = $sth->fetch()) { - return $row["value"]; - } else { - if ($no_update) { - return -1; - } else { - return CCache::update($feed_id, $owner_uid, $is_cat); - } - } - - } - - static function update($feed_id, $owner_uid, $is_cat = false, - $update_pcat = true, $pcat_fast = false) { - - // "" (null) is valid and should be cast to 0 (uncategorized) - // everything else i.e. tags are not - if (!is_numeric($feed_id) && $feed_id) - return; - - $feed_id = (int) $feed_id; - - $prev_unread = CCache::find($feed_id, $owner_uid, $is_cat, true); - - /* When updating a label, all we need to do is recalculate feed counters - * because labels are not cached */ - - if ($feed_id < 0) { - CCache::update_all($owner_uid); - return; - } - - if (!$is_cat) { - $table = "ttrss_counters_cache"; - } else { - $table = "ttrss_cat_counters_cache"; - } - - $pdo = Db::pdo(); - - if ($is_cat && $feed_id >= 0) { - /* Recalculate counters for child feeds */ - - if (!$pcat_fast) { - $sth = $pdo->prepare("SELECT id FROM ttrss_feeds - WHERE owner_uid = :uid AND - (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))"); - $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]); - - while ($line = $sth->fetch()) { - CCache::update((int)$line["id"], $owner_uid, false, false); - } - } - - $sth = $pdo->prepare("SELECT SUM(value) AS sv - FROM ttrss_counters_cache, ttrss_feeds - WHERE ttrss_feeds.id = feed_id AND - (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND - ttrss_counters_cache.owner_uid = :uid AND - ttrss_feeds.owner_uid = :uid"); - $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]); - $row = $sth->fetch(); - - $unread = (int) $row["sv"]; - - } else { - $unread = (int) Feeds::getFeedArticles($feed_id, $is_cat, true, $owner_uid); - } - - $tr_in_progress = false; - - try { - $pdo->beginTransaction(); - } catch (Exception $e) { - $tr_in_progress = true; - } - - $sth = $pdo->prepare("SELECT feed_id FROM $table - WHERE owner_uid = ? AND feed_id = ? LIMIT 1"); - $sth->execute([$owner_uid, $feed_id]); - - if ($sth->fetch()) { - - $sth = $pdo->prepare("UPDATE $table SET - value = ?, updated = NOW() WHERE - feed_id = ? AND owner_uid = ?"); - - $sth->execute([$unread, $feed_id, $owner_uid]); - - } else { - $sth = $pdo->prepare("INSERT INTO $table - (feed_id, value, owner_uid, updated) - VALUES - (?, ?, ?, NOW())"); - $sth->execute([$feed_id, $unread, $owner_uid]); - } - - if (!$tr_in_progress) $pdo->commit(); - - if ($feed_id > 0 && $prev_unread != $unread) { - - if (!$is_cat) { - - /* Update parent category */ - - if ($update_pcat) { - - $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds - WHERE owner_uid = ? AND id = ?"); - $sth->execute([$owner_uid, $feed_id]); - - if ($row = $sth->fetch()) { - CCache::update((int)$row["cat_id"], $owner_uid, true, true, true); - } - } - } - } else if ($feed_id < 0) { - CCache::update_all($owner_uid); - } - - return $unread; - } - -} \ No newline at end of file diff --git a/classes/counters.php b/classes/counters.php index cee901304..29a7812b6 100644 --- a/classes/counters.php +++ b/classes/counters.php @@ -13,174 +13,84 @@ class Counters { } static function getCategoryCounters() { - $ret_arr = array(); + $ret = []; /* Labels category */ $cv = array("id" => -2, "kind" => "cat", "counter" => Feeds::getCategoryUnread(-2)); - array_push($ret_arr, $cv); + array_push($ret, $cv); $pdo = DB::pdo(); - $sth = $pdo->prepare("SELECT ttrss_feed_categories.id AS cat_id, value AS unread, - (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 - WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children - FROM ttrss_feed_categories, ttrss_cat_counters_cache - WHERE ttrss_cat_counters_cache.feed_id = ttrss_feed_categories.id AND - ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid AND - ttrss_feed_categories.owner_uid = ?"); - $sth->execute([$_SESSION['uid']]); + $sth = $pdo->prepare("SELECT fc.id, + SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count, + SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked, + (SELECT COUNT(id) FROM ttrss_feed_categories fcc + WHERE fcc.parent_cat = fc.id) AS num_children + FROM ttrss_feed_categories fc, ttrss_feeds f, ttrss_user_entries ue + WHERE f.cat_id = fc.id AND + ue.feed_id = f.id AND + ue.owner_uid = :uid + GROUP BY fc.id + UNION + SELECT 0, + SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count, + SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked, + 0 + FROM ttrss_feeds f, ttrss_user_entries ue + WHERE f.cat_id IS NULL AND + ue.feed_id = f.id AND + ue.owner_uid = :uid"); + + $sth->execute(["uid" => $_SESSION['uid']]); while ($line = $sth->fetch()) { - $line["cat_id"] = (int) $line["cat_id"]; - if ($line["num_children"] > 0) { $child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]); } else { $child_counter = 0; } - $cv = array("id" => $line["cat_id"], "kind" => "cat", - "counter" => $line["unread"] + $child_counter); + $cv = [ + "id" => (int)$line["id"], + "kind" => "cat", + "markedcounter" => (int) $line["count_marked"], + "counter" => (int) $line["count"] + $child_counter + ]; - array_push($ret_arr, $cv); + array_push($ret, $cv); } - /* Special case: NULL category doesn't actually exist in the DB */ + array_push($ret, $cv); - $cv = array("id" => 0, "kind" => "cat", - "counter" => (int) CCache::find(0, $_SESSION["uid"], true)); - - array_push($ret_arr, $cv); - - return $ret_arr; + return $ret; } - static function getGlobalCounters($global_unread = -1) { - $ret_arr = array(); - - if ($global_unread == -1) { - $global_unread = Feeds::getGlobalUnread(); - } - - $cv = array("id" => "global-unread", - "counter" => (int) $global_unread); - - array_push($ret_arr, $cv); - - $pdo = Db::pdo(); - - $sth = $pdo->prepare("SELECT COUNT(id) AS fn FROM - ttrss_feeds WHERE owner_uid = ?"); - $sth->execute([$_SESSION['uid']]); - $row = $sth->fetch(); - - $subscribed_feeds = $row["fn"]; - - $cv = array("id" => "subscribed-feeds", - "counter" => (int) $subscribed_feeds); - - array_push($ret_arr, $cv); - - return $ret_arr; - } - - static function getVirtCounters() { - - $ret_arr = array(); - - for ($i = 0; $i >= -4; $i--) { - - $count = getFeedUnread($i); - - if ($i == 0 || $i == -1 || $i == -2) - $auxctr = Feeds::getFeedArticles($i, false); - else - $auxctr = 0; - - $cv = array("id" => $i, - "counter" => (int) $count, - "auxcounter" => (int) $auxctr); - -// if (get_pref('EXTENDED_FEEDLIST')) -// $cv["xmsg"] = getFeedArticles($i)." ".__("total"); - - array_push($ret_arr, $cv); - } - - $feeds = PluginHost::getInstance()->get_feeds(-1); - - if (is_array($feeds)) { - foreach ($feeds as $feed) { - $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), - "counter" => $feed['sender']->get_unread($feed['id'])); - - if (method_exists($feed['sender'], 'get_total')) - $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); - - array_push($ret_arr, $cv); - } - } - - return $ret_arr; - } - - static function getLabelCounters($descriptions = false) { - - $ret_arr = array(); - - $pdo = Db::pdo(); - - $sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total - FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON - (ttrss_labels2.id = label_id) - LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id - WHERE ttrss_labels2.owner_uid = :uid AND u1.owner_uid = :uid - GROUP BY ttrss_labels2.id, - ttrss_labels2.caption"); - $sth->execute([":uid" => $_SESSION['uid']]); - - while ($line = $sth->fetch()) { - - $id = Labels::label_to_feed_id($line["id"]); - - $cv = array("id" => $id, - "counter" => (int) $line["unread"], - "auxcounter" => (int) $line["total"]); - - if ($descriptions) - $cv["description"] = $line["caption"]; - - array_push($ret_arr, $cv); - } - - return $ret_arr; - } static function getFeedCounters($active_feed = false) { - $ret_arr = array(); + $ret = []; $pdo = Db::pdo(); - $sth = $pdo->prepare("SELECT ttrss_feeds.id, - ttrss_feeds.title, - ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, - last_error, value AS count - FROM ttrss_feeds, ttrss_counters_cache - WHERE ttrss_feeds.owner_uid = ? - AND ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid - AND ttrss_counters_cache.feed_id = ttrss_feeds.id"); + $sth = $pdo->prepare("SELECT f.id, + f.title, + ".SUBSTRING_FOR_DATE."(f.last_updated,1,19) AS last_updated, + f.last_error, + SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count, + SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked + FROM ttrss_feeds f, ttrss_user_entries ue + WHERE f.id = ue.feed_id AND ue.owner_uid = :uid + GROUP BY f.id"); + $sth->execute([$_SESSION['uid']]); while ($line = $sth->fetch()) { $id = $line["id"]; - $count = $line["count"]; $last_error = htmlspecialchars($line["last_error"]); - $last_updated = make_local_datetime($line['last_updated'], false); if (Feeds::feedHasIcon($id)) { @@ -192,25 +102,134 @@ class Counters { if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) $last_updated = ''; - $cv = array("id" => $id, + $cv = [ + "id" => $id, "updated" => $last_updated, - "counter" => (int) $count, - "has_img" => (int) $has_img); + "counter" => (int) $line["count"], + "markedcounter" => (int) $line["count_marked"], + "has_img" => (int) $has_img + ]; if ($last_error) $cv["error"] = $last_error; -// if (get_pref('EXTENDED_FEEDLIST')) -// $cv["xmsg"] = getFeedArticles($id)." ".__("total"); - if ($active_feed && $id == $active_feed) $cv["title"] = truncate_string($line["title"], 30); - array_push($ret_arr, $cv); + array_push($ret, $cv); } - return $ret_arr; + return $ret; } -} \ No newline at end of file + static function getGlobalCounters($global_unread = -1) { + $ret = []; + + if ($global_unread == -1) { + $global_unread = Feeds::getGlobalUnread(); + } + + $cv = [ + "id" => "global-unread", + "counter" => (int) $global_unread + ]; + + array_push($ret, $cv); + + $pdo = Db::pdo(); + + $sth = $pdo->prepare("SELECT COUNT(id) AS fn FROM + ttrss_feeds WHERE owner_uid = ?"); + $sth->execute([$_SESSION['uid']]); + $row = $sth->fetch(); + + $subscribed_feeds = $row["fn"]; + + $cv = [ + "id" => "subscribed-feeds", + "counter" => (int) $subscribed_feeds + ]; + + array_push($ret, $cv); + + return $ret; + } + + static function getVirtCounters() { + + $ret = []; + + for ($i = 0; $i >= -4; $i--) { + + $count = getFeedUnread($i); + + if ($i == 0 || $i == -1 || $i == -2) + $auxctr = Feeds::getFeedArticles($i, false); + else + $auxctr = 0; + + $cv = [ + "id" => $i, + "counter" => (int) $count, + "auxcounter" => (int) $auxctr + ]; + + array_push($ret, $cv); + } + + $feeds = PluginHost::getInstance()->get_feeds(-1); + + if (is_array($feeds)) { + foreach ($feeds as $feed) { + $cv = [ + "id" => PluginHost::pfeed_to_feed_id($feed['id']), + "counter" => $feed['sender']->get_unread($feed['id']) + ]; + + if (method_exists($feed['sender'], 'get_total')) + $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); + + array_push($ret, $cv); + } + } + + return $ret; + } + + static function getLabelCounters($descriptions = false) { + + $ret = []; + + $pdo = Db::pdo(); + + $sth = $pdo->prepare("SELECT id, + caption, + SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, + COUNT(u1.unread) AS total + FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON + (ttrss_labels2.id = label_id) + LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id + WHERE ttrss_labels2.owner_uid = :uid AND u1.owner_uid = :uid + GROUP BY ttrss_labels2.id, ttrss_labels2.caption"); + $sth->execute([":uid" => $_SESSION['uid']]); + + while ($line = $sth->fetch()) { + + $id = Labels::label_to_feed_id($line["id"]); + + $cv = [ + "id" => $id, + "counter" => (int) $line["unread"], + "auxcounter" => (int) $line["total"] + ]; + + if ($descriptions) + $cv["description"] = $line["caption"]; + + array_push($ret, $cv); + } + + return $ret; + } +} diff --git a/classes/feeds.php b/classes/feeds.php index 2f55664e1..2aa7333fd 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -457,8 +457,6 @@ class Feeds extends Handler_Protected { $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET last_read = NOW(), unread = false WHERE unread = true AND owner_uid = ?"); $sth->execute([$_SESSION['uid']]); - - CCache::zero_all($_SESSION["uid"]); } function view() { @@ -512,13 +510,6 @@ class Feeds extends Handler_Protected { return; } - /* Updating a label ccache means recalculating all of the caches - * so for performance reasons we don't do that here */ - - if ($feed >= 0) { - CCache::update($feed, $_SESSION["uid"], $cat_view); - } - set_pref("_DEFAULT_VIEW_MODE", $view_mode); set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by); @@ -1013,8 +1004,6 @@ class Feeds extends Handler_Protected { } - CCache::update($feed, $owner_uid, $cat_view); - } else { // tag $sth = $pdo->prepare("UPDATE ttrss_user_entries SET unread = false, last_read = NOW() WHERE ref_id IN @@ -1381,12 +1370,14 @@ class Feeds extends Handler_Protected { $pdo = Db::pdo(); - $sth = $pdo->prepare("SELECT SUM(value) AS c_id FROM ttrss_counters_cache - WHERE owner_uid = ? AND feed_id > 0"); + $sth = $pdo->prepare("SELECT SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count + FROM ttrss_user_entries ue + WHERE ue.owner_uid = ?"); + $sth->execute([$user_id]); $row = $sth->fetch(); - return $row["c_id"]; + return $row["count"]; } static function getCategoryTitle($cat_id) { @@ -2116,9 +2107,6 @@ class Feeds extends Handler_Protected { } if ($purge_interval == -1 || !$purge_interval) { - if ($owner_uid) { - CCache::update($feed_id, $owner_uid); - } return; } @@ -2163,8 +2151,6 @@ class Feeds extends Handler_Protected { $rows = $sth->rowCount(); - CCache::update($feed_id, $owner_uid); - Debug::log("Purged feed $feed_id ($purge_interval): deleted $rows articles"); return $rows; diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index f672a0375..b3aeec086 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1389,17 +1389,11 @@ class Pref_Feeds extends Handler_Protected { $obj = array(); $cat_id = (int) $cat_id; - if ($cat_id > 0) { - $cat_unread = CCache::find($cat_id, $_SESSION["uid"], true); - } else if ($cat_id == 0 || $cat_id == -2) { - $cat_unread = Feeds::getCategoryUnread($cat_id); - } - $obj['id'] = 'CAT:' . $cat_id; $obj['items'] = array(); $obj['name'] = Feeds::getCategoryTitle($cat_id); $obj['type'] = 'category'; - $obj['unread'] = (int) $cat_unread; + $obj['unread'] = (int) Feeds::getCategoryUnread($cat_id); $obj['bare_id'] = $cat_id; return $obj; @@ -1562,12 +1556,9 @@ class Pref_Feeds extends Handler_Protected { } private function remove_feed_category($id, $owner_uid) { - $sth = $this->pdo->prepare("DELETE FROM ttrss_feed_categories WHERE id = ? AND owner_uid = ?"); $sth->execute([$id, $owner_uid]); - - CCache::remove($id, $owner_uid, true); } static function remove_feed($id, $owner_uid) { @@ -1640,11 +1631,8 @@ class Pref_Feeds extends Handler_Protected { unlink(ICONS_DIR . "/$id.ico"); } - CCache::remove($id, $owner_uid); - } else { Labels::remove(Labels::feed_to_label_id($id), $owner_uid); - //CCache::remove($id, $owner_uid); don't think labels are cached } } diff --git a/classes/rssutils.php b/classes/rssutils.php index 66008899b..831ac1baf 100755 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -1469,26 +1469,12 @@ class RSSUtils { mb_strtolower(strip_tags($title), 'utf-8')); } + /* counter cache is no longer used, if called truncate leftover data */ static function cleanup_counters_cache() { $pdo = Db::pdo(); - $res = $pdo->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 = $res->rowCount(); - - $res = $pdo->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 = $res->rowCount(); - - Debug::log("Removed $frows (feeds) $crows (cats) orphaned counter cache entries."); + $pdo->query("DELETE FROM ttrss_counters_cache"); + $pdo->query("DELETE FROM ttrss_cat_counters_cache"); } static function housekeeping_user($owner_uid) { diff --git a/include/functions.php b/include/functions.php index 42b05ff15..ce8a07d51 100644 --- a/include/functions.php +++ b/include/functions.php @@ -731,24 +731,7 @@ if ($_SESSION["uid"]) { startup_gettext(); load_user_plugins($_SESSION["uid"]); - - /* cleanup ccache */ - - $sth = $pdo->prepare("DELETE FROM ttrss_counters_cache WHERE owner_uid = ? - AND - (SELECT COUNT(id) FROM ttrss_feeds WHERE - ttrss_feeds.id = feed_id) = 0"); - - $sth->execute([$_SESSION['uid']]); - - $sth = $pdo->prepare("DELETE FROM ttrss_cat_counters_cache WHERE owner_uid = ? - AND - (SELECT COUNT(id) FROM ttrss_feed_categories WHERE - ttrss_feed_categories.id = feed_id) = 0"); - - $sth->execute([$_SESSION['uid']]); } - } }