From 4d8f4c59894b27204ebe2042d0d3c0de477af4cf Mon Sep 17 00:00:00 2001 From: Roland Angerer Date: Tue, 17 Sep 2013 12:05:13 +0200 Subject: [PATCH] optimized query for label counters --- include/functions.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/functions.php b/include/functions.php index 2f16ea58..55896b66 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1557,13 +1557,10 @@ $owner_uid = $_SESSION["uid"]; - $result = db_query("SELECT id,caption,COUNT(u1.unread) AS unread,COUNT(u2.unread) AS total + $result = db_query("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON (ttrss_labels2.id = label_id) - LEFT JOIN ttrss_user_entries AS u1 ON (u1.ref_id = article_id AND u1.unread = true - AND u1.owner_uid = $owner_uid) - LEFT JOIN ttrss_user_entries AS u2 ON (u2.ref_id = article_id AND u2.unread = false - AND u2.owner_uid = $owner_uid) + LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id WHERE ttrss_labels2.owner_uid = $owner_uid GROUP BY ttrss_labels2.id, ttrss_labels2.caption"); -- 2.39.5