From 45942238bfdb8e7c8f3ee8f6331945b31c5d7039 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 27 Feb 2013 15:05:38 +0400 Subject: [PATCH] getLabelCounters: optimize SQL --- include/functions.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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); -- 2.39.5