]> git.wh0rd.org Git - tt-rss.git/commitdiff
ccache: performance tweaks
authorAndrew Dolgov <fox@bah.spb.su>
Sat, 17 Jan 2009 12:50:29 +0000 (13:50 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sat, 17 Jan 2009 12:50:29 +0000 (13:50 +0100)
backend.php
functions.php

index 28a3eba261c8df9adeec9f7cb000f149a50f2c2b..2fb3d8f9dc900a2adf17c5ca5fbc504f96f124eb 100644 (file)
                        $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);
index 9072b981b1a3c66563370bad4ca98e7206566b09..aecf4b37e9c2738864a4706d0783f91c70ddd2bb 100644 (file)
                        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";
                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";
                                $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 
                                
                }
 
-               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);
-
                        }
                }