]> git.wh0rd.org Git - tt-rss.git/commitdiff
getLabelCounters: optimize SQL
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 27 Feb 2013 11:05:38 +0000 (15:05 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 27 Feb 2013 11:05:38 +0000 (15:05 +0400)
include/functions.php

index 00193c995fd6f66fc82bf770bbe91b8108c0b128..ec91bd3fa6df8875c6e4523a4a60c77d2ff070a3 100644 (file)
 
                $owner_uid = $_SESSION["uid"];
 
-               $result = db_query($link, "SELECT id, caption FROM ttrss_labels2
-                       WHERE owner_uid = '$owner_uid'");
+               $result = db_query($link, "SELECT id,caption,COUNT(unread) AS unread
+                       FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
+                               (ttrss_labels2.id = label_id)
+                                       LEFT JOIN ttrss_user_entries ON (ref_id = article_id AND unread = true)
+                       WHERE ttrss_labels2.owner_uid = $owner_uid GROUP BY ttrss_labels2.id");
 
                while ($line = db_fetch_assoc($result)) {
 
                        $id = -$line["id"] - 11;
 
                        $label_name = $line["caption"];
-                       $count = getFeedUnread($link, $id);
+                       $count = $line["unread"];
 
                        $cv = array("id" => $id,
                                "counter" => (int) $count);