ccache: performance tweaks

master
Andrew Dolgov 16 years ago
parent 1be2f3b6ec
commit 6b49a3dd7b

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

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

Loading…
Cancel
Save