From 0eeac4a669e46fb6521ae1765b23656c9afc43de Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 21 Jul 2024 14:54:34 +0200 Subject: Revisit keepMaxUnreads (#6632) * Revisit keepMaxUnreads Again, follow-up of https://github.com/FreshRSS/FreshRSS/pull/5905 fix https://github.com/FreshRSS/FreshRSS/issues/6620 * Refactoring to address buggy cases * Fix minor test --- app/Models/EntryDAO.php | 43 ++++++------------------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) (limited to 'app/Models/EntryDAO.php') diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 0b289eb41..ec627dda1 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -274,45 +274,14 @@ SQL; } /** - * Count the number of new entries in the temporary table (which have not yet been committed), grouped by read / unread. - * @return array{'all':int,'unread':int,'read':int} + * Count the number of new entries in the temporary table (which have not yet been committed). */ - public function countNewEntries(): array { + public function countNewEntries(): int { $sql = <<<'SQL' - SELECT is_read, COUNT(id) AS nb_entries FROM `_entrytmp` - GROUP BY is_read + SELECT COUNT(id) AS nb_entries FROM `_entrytmp` SQL; - $lines = $this->fetchAssoc($sql) ?? []; - $nbRead = 0; - $nbUnread = 0; - foreach ($lines as $line) { - if (empty($line['is_read'])) { - $nbUnread = (int)($line['nb_entries'] ?? 0); - } else { - $nbRead = (int)($line['nb_entries'] ?? 0); - } - } - return ['all' => $nbRead + $nbUnread, 'unread' => $nbUnread, 'read' => $nbRead]; - } - - /** - * Count the number of new unread entries in the temporary table (which have not yet been committed), grouped by feed ID. - * @return array - */ - public function newUnreadEntriesPerFeed(): array { - $sql = <<<'SQL' - SELECT id_feed, COUNT(id) AS nb_entries FROM `_entrytmp` - WHERE is_read = 0 - GROUP BY id_feed - SQL; - $lines = $this->fetchAssoc($sql) ?? []; - $result = []; - foreach ($lines as $line) { - if (!empty($line['id_feed'])) { - $result[(int)$line['id_feed']] = (int)($line['nb_entries'] ?? 0); - } - } - return $result; + $res = $this->fetchColumn($sql, 0); + return isset($res[0]) ? (int)$res[0] : -1; } /** @@ -651,7 +620,7 @@ SQL; } /** - * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after. + * Remember to call updateCachedValues($id_feed) or updateCachedValues() just after. * @param array $options * @return int|false */ -- cgit v1.2.3