summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-01-25 09:57:28 +0300
committerAndrew Dolgov <[email protected]>2020-01-25 09:57:28 +0300
commita6ced361890ab44e049369ac63a74b63f8820b7e (patch)
tree3c8e00310dcdc5c17bae1e11eab484a466eb3c9f
parentdeefa901abecef39f1955436af213d9a64d65160 (diff)
getCategoryCounters: properly calculate counters for child subcategory entries
getCategoryUnread: cleanup
-rw-r--r--classes/counters.php2
-rwxr-xr-xclasses/feeds.php48
2 files changed, 15 insertions, 35 deletions
diff --git a/classes/counters.php b/classes/counters.php
index a0e39ea52..b65f0adeb 100644
--- a/classes/counters.php
+++ b/classes/counters.php
@@ -48,7 +48,7 @@ class Counters {
while ($line = $sth->fetch()) {
if ($line["num_children"] > 0) {
- $child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]);
+ $child_counter = Feeds::getCategoryChildrenUnread($line["id"], $_SESSION["uid"]);
} else {
$child_counter = 0;
}
diff --git a/classes/feeds.php b/classes/feeds.php
index d24fcdee9..c6a2cf66b 100755
--- a/classes/feeds.php
+++ b/classes/feeds.php
@@ -1298,46 +1298,26 @@ class Feeds extends Handler_Protected {
if ($cat >= 0) {
- if (!$cat) $cat = null;
-
- $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
- WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL))
- AND owner_uid = :uid");
-
- $sth->execute([":cat" => $cat, ":uid" => $owner_uid]);
-
- $cat_feeds = array();
- while ($line = $sth->fetch()) {
- array_push($cat_feeds, "feed_id = " . (int)$line["id"]);
- }
-
- if (count($cat_feeds) == 0) return 0;
-
- $match_part = implode(" OR ", $cat_feeds);
-
- $sth = $pdo->prepare("SELECT COUNT(int_id) AS unread
+ $sth = $pdo->prepare("SELECT SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS unread
FROM ttrss_user_entries
- WHERE unread = true AND ($match_part)
- AND owner_uid = ?");
- $sth->execute([$owner_uid]);
-
- $unread = 0;
+ WHERE feed_id IN (SELECT id FROM ttrss_feeds
+ WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL))
+ AND owner_uid = :uid)
+ AND owner_uid = :uid");
+ $sth->execute(["cat" => $cat ? $cat : null, "uid" => $owner_uid]);
+ $row = $sth->fetch();
- # this needs to be rewritten
- while ($line = $sth->fetch()) {
- $unread += $line["unread"];
- }
+ return $row["unread"];
- return $unread;
} else if ($cat == -1) {
return 0;
} else if ($cat == -2) {
- $sth = $pdo->prepare("SELECT COUNT(unread) AS unread FROM
- ttrss_user_entries, ttrss_user_labels2
- WHERE article_id = ref_id AND unread = true
- AND ttrss_user_entries.owner_uid = ?");
- $sth->execute([$owner_uid]);
+ $sth = $pdo->prepare("SELECT SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS unread FROM
+ ttrss_user_entries ue, ttrss_user_labels2 l
+ WHERE article_id = ref_id AND
+ ue.owner_uid = :uid");
+ $sth->execute(["uid" => $owner_uid]);
$row = $sth->fetch();
return $row["unread"];
@@ -1357,7 +1337,7 @@ class Feeds extends Handler_Protected {
$unread = 0;
while ($line = $sth->fetch()) {
- $unread += Feeds::getCategoryUnread($line["id"], $owner_uid);
+ $unread += Feeds::getCategoryUnread($line["id"], $owner_uid) +
$unread += Feeds::getCategoryChildrenUnread($line["id"], $owner_uid);
}