From 0477a326a94ccc4fea44ac2ee014204fabe70fe8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 29 Nov 2005 14:42:37 +0100 Subject: [PATCH] store previous value of counters and send only diffs --- backend.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/backend.php b/backend.php index 85ab14ec1..5c7fa491b 100644 --- a/backend.php +++ b/backend.php @@ -73,8 +73,18 @@ print ""; } - function getTagCounters($link) { - + function getTagCounters($link, $smart_mode = true) { + + if ($smart_mode) { + if (!$_SESSION["tctr_last_value"]) { + $_SESSION["tctr_last_value"] = array(); + } + } + + $old_counters = $_SESSION["tctr_last_value"]; + + $tctrs_modified = false; + $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE ttrss_user_entries.ref_id = ttrss_entries.id AND @@ -94,8 +104,19 @@ $unread = $tags[$tag]; $tag = htmlspecialchars($tag); - print ""; + + if (!$smart_mode || $old_counters[$tag] != $unread) { + $old_counters[$tag] = $unread; + $tctrs_modified = true; + print ""; + } + } + + if ($smart_mode && $tctrs_modified) { + $_SESSION["tctr_last_value"] = $old_counters; + } + } function getLabelCounters($link) { @@ -143,21 +164,39 @@ print ""; } - function getFeedCounters($link) { - + function getFeedCounters($link, $smart_mode = true) { + + if ($smart_mode) { + if (!$_SESSION["fctr_last_value"]) { + $_SESSION["fctr_last_value"] = array(); + } + } + + $old_counters = $_SESSION["fctr_last_value"]; + $result = db_query($link, "SELECT id, (SELECT count(id) FROM ttrss_entries,ttrss_user_entries WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); - + + $fctrs_modified = false; + while ($line = db_fetch_assoc($result)) { $id = $line["id"]; $count = $line["count"]; - print ""; + if (!$smart_mode || $old_counters[$id] != $count) { + $old_counters[$id] = $count; + $fctrs_modified = true; + print ""; + } + } + + if ($smart_mode && $fctrs_modified) { + $_SESSION["fctr_last_value"] = $old_counters; } }