Merge pull request #299 from rangerer/label_counters

optimized query for label counters
This commit is contained in:
Andrew Dolgov 2013-09-17 03:27:07 -07:00
commit 80c448cb98

View file

@ -1557,13 +1557,10 @@
$owner_uid = $_SESSION["uid"]; $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 FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
(ttrss_labels2.id = label_id) (ttrss_labels2.id = label_id)
LEFT JOIN ttrss_user_entries AS u1 ON (u1.ref_id = article_id AND u1.unread = true LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id
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)
WHERE ttrss_labels2.owner_uid = $owner_uid GROUP BY ttrss_labels2.id, WHERE ttrss_labels2.owner_uid = $owner_uid GROUP BY ttrss_labels2.id,
ttrss_labels2.caption"); ttrss_labels2.caption");