ccache: performance tweaks

This commit is contained in:
Andrew Dolgov 2009-01-17 13:50:29 +01:00
parent 1be2f3b6ec
commit 6b49a3dd7b
2 changed files with 35 additions and 32 deletions

View File

@ -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);

View File

@ -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";
@ -5969,14 +5970,20 @@
if (db_num_rows($result) == 1) {
return db_fetch_result($result, 0, "value");
} else {
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,10 +6034,14 @@
}
if ($feed_id > 0 && !$direct_only) {
if ($feed_id > 0 && $prev_unread != $unread) {
if (!$is_cat) {
/* Update parent category */
if ($update_pcat) {
$result = db_query($link, "SELECT cat_id FROM ttrss_feeds
WHERE owner_uid = '$owner_uid' AND id = '$feed_id'");
@ -6029,33 +6049,16 @@
ccache_update($link, $cat_id, $owner_uid, true);
}
/* Update possibly referenced labels */
$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["feed_id"], $owner_uid);
}
} else {
if ($feed_id == 0) {
$cat_qpart = "cat_id IS NULL";
} else {
$cat_qpart = "cat_id = '$feed_id'";
}
/* Update counters for our 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, true);
}
/* With that done, update our own counter again */
ccache_update($link, $feed_id, $owner_uid, true, true);
}
}