diff options
| author | 2024-07-21 14:54:34 +0200 | |
|---|---|---|
| committer | 2024-07-21 14:54:34 +0200 | |
| commit | 0eeac4a669e46fb6521ae1765b23656c9afc43de (patch) | |
| tree | 7c5a08b80b628f855b11c8850aa993c0b509feb1 /app/Models/EntryDAO.php | |
| parent | 47b5e40e7240b5ccb0d0b6c54e0a958243689c83 (diff) | |
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
Diffstat (limited to 'app/Models/EntryDAO.php')
| -rw-r--r-- | app/Models/EntryDAO.php | 43 |
1 files changed, 6 insertions, 37 deletions
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<int,int> - */ - 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<string,bool|int|string> $options * @return int|false */ |
