From: Andrew Dolgov Date: Wed, 27 Feb 2013 11:05:38 +0000 (+0400) Subject: getLabelCounters: optimize SQL X-Git-Tag: 1.7.1~29 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=45942238bfdb8e7c8f3ee8f6331945b31c5d7039;p=tt-rss.git getLabelCounters: optimize SQL --- diff --git a/include/functions.php b/include/functions.php index 00193c99..ec91bd3f 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1413,15 +1413,18 @@ $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);