From 553548b6897f8ef292ab56af9dcc196ef8ee0cb3 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 24 Feb 2021 15:07:31 +0300 Subject: request label counters conditionally --- classes/article.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'classes/article.php') diff --git a/classes/article.php b/classes/article.php index f77275122..6baf8f068 100755 --- a/classes/article.php +++ b/classes/article.php @@ -640,10 +640,41 @@ class Article extends Handler_Protected { return [$article_image, $article_stream, $article_kind]; } + // only cached, returns label ids (not label feed ids) + static function _labels_of(array $article_ids) { + if (count($article_ids) == 0) + return []; + + $id_qmarks = arr_qmarks($article_ids); + + $sth = Db::pdo()->prepare("SELECT DISTINCT label_cache FROM ttrss_entries e, ttrss_user_entries ue + WHERE ue.ref_id = e.id AND id IN ($id_qmarks)"); + + $sth->execute($article_ids); + + $rv = []; + + while ($row = $sth->fetch()) { + $labels = json_decode($row["label_cache"]); + + if (isset($labels) && is_array($labels)) { + foreach ($labels as $label) { + if (empty($label["no-labels"])) + array_push($rv, Labels::feed_to_label_id($label[0])); + } + } + } + + return array_unique($rv); + } + static function _feeds_of(array $article_ids) { + if (count($article_ids) == 0) + return []; + $id_qmarks = arr_qmarks($article_ids); - $sth = DB::pdo()->prepare("SELECT DISTINCT feed_id FROM ttrss_entries e, ttrss_user_entries ue + $sth = Db::pdo()->prepare("SELECT DISTINCT feed_id FROM ttrss_entries e, ttrss_user_entries ue WHERE ue.ref_id = e.id AND id IN ($id_qmarks)"); $sth->execute($article_ids); -- cgit v1.2.3