From 6b49a3dd7bee0c2f006b06dd0bbcabf4e4829a9e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 17 Jan 2009 13:50:29 +0100 Subject: [PATCH] ccache: performance tweaks --- backend.php | 6 +++--- functions.php | 57 +++++++++++++++++++++++++++------------------------ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/backend.php b/backend.php index 28a3eba2..2fb3d8f9 100644 --- a/backend.php +++ b/backend.php @@ -270,9 +270,9 @@ $csync = $_GET["csync"]; $order_by = db_escape_string($_GET["order_by"]); - if (!$cat_view) { - ccache_update($link, $feed, $_SESSION["uid"], $cat_view); - } +// if (!$cat_view) { +// ccache_update($link, $feed, $_SESSION["uid"], $cat_view); +// } set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode); set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit); diff --git a/functions.php b/functions.php index 9072b981..aecf4b37 100644 --- a/functions.php +++ b/functions.php @@ -5949,7 +5949,8 @@ WHERE feed_id = '$feed_id' AND owner_uid = '$owner_uid'"); } */ - function ccache_find($link, $feed_id, $owner_uid, $is_cat = false) { + function ccache_find($link, $feed_id, $owner_uid, $is_cat = false, + $no_update = false) { if (!$is_cat) { $table = "ttrss_counters_cache"; @@ -5970,13 +5971,19 @@ if (db_num_rows($result) == 1) { return db_fetch_result($result, 0, "value"); } else { - return ccache_update($link, $feed_id, $owner_uid, $is_cat); + if ($no_update) { + return -1; + } else { + return ccache_update($link, $feed_id, $owner_uid, $is_cat); + } } } function ccache_update($link, $feed_id, $owner_uid, $is_cat = false, - $direct_only = false) { + $update_pcat = true) { + + $prev_unread = ccache_find($link, $feed_id, $owner_uid, $is_cat, true); if (!$is_cat) { $table = "ttrss_counters_cache"; @@ -5991,6 +5998,15 @@ $cat_qpart = "cat_id IS NULL"; } + /* Recalculate counters for child feeds */ + + $result = db_query($link, "SELECT id FROM ttrss_feeds + WHERE owner_uid = '$owner_uid' AND $cat_qpart"); + + while ($line = db_fetch_assoc($result)) { + ccache_update($link, $line["id"], $owner_uid, false, false); + } + $result = db_query($link, "SELECT SUM(value) AS sv FROM ttrss_counters_cache, ttrss_feeds WHERE id = feed_id AND $cat_qpart AND @@ -6018,44 +6034,31 @@ } - if ($feed_id > 0 && !$direct_only) { + if ($feed_id > 0 && $prev_unread != $unread) { if (!$is_cat) { - $result = db_query($link, "SELECT cat_id FROM ttrss_feeds - WHERE owner_uid = '$owner_uid' AND id = '$feed_id'"); + /* Update parent category */ - $cat_id = (int) db_fetch_result($result, 0, "cat_id"); + if ($update_pcat) { - ccache_update($link, $cat_id, $owner_uid, true); + $result = db_query($link, "SELECT cat_id FROM ttrss_feeds + WHERE owner_uid = '$owner_uid' AND id = '$feed_id'"); - $result = db_query($link, "SELECT feed_id FROM ttrss_counters_cache - WHERE owner_uid = '$owner_uid' AND feed_id < 0"); + $cat_id = (int) db_fetch_result($result, 0, "cat_id"); - while ($line = db_fetch_assoc($result)) { - ccache_update($link, $line["feed_id"], $owner_uid); - } - } else { + ccache_update($link, $cat_id, $owner_uid, true); - if ($feed_id == 0) { - $cat_qpart = "cat_id IS NULL"; - } else { - $cat_qpart = "cat_id = '$feed_id'"; } - /* Update counters for our child feeds */ + /* Update possibly referenced labels */ - $result = db_query($link, "SELECT id FROM ttrss_feeds - WHERE owner_uid = '$owner_uid' AND $cat_qpart"); + $result = db_query($link, "SELECT feed_id FROM ttrss_counters_cache + WHERE owner_uid = '$owner_uid' AND feed_id < 0"); while ($line = db_fetch_assoc($result)) { - ccache_update($link, $line["id"], $owner_uid, false, true); + ccache_update($link, $line["feed_id"], $owner_uid); } - - /* With that done, update our own counter again */ - - ccache_update($link, $feed_id, $owner_uid, true, true); - } } -- 2.39.5