From bfd277065c7bfd28779c585549dd9e9e577eabdf Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 26 Feb 2024 09:01:25 +0100 Subject: Improve feed refresh (#6117) * Improve feed refresh Better account for some edge cases for cron and automatic labels fix https://github.com/FreshRSS/FreshRSS/issues/6089 fix https://github.com/FreshRSS/FreshRSS/issues/6109 * Apply labels also to new entries already marked as read * Add case most relevant for cron --- app/Models/EntryDAO.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'app/Models/EntryDAO.php') diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index f770ce400..bb0b9af43 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -274,7 +274,29 @@ SQL; } /** - * Count the number of new entries in the temporary table (which have not yet been committed), grouped by feed ID. + * 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} + */ + public function countNewEntries(): array { + $sql = <<<'SQL' + SELECT is_read, COUNT(id) AS nb_entries FROM `_entrytmp` + GROUP BY is_read + 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 { -- cgit v1.2.3