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/FeedDAO.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'app/Models/FeedDAO.php') diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index c0b2e9e7a..4a75e3dea 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -203,7 +203,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { /** * @return int|false - * @see updateCachedValue() + * @see updateCachedValues() */ public function updateLastUpdate(int $id, bool $inError = false, int $mtime = 0) { $sql = 'UPDATE `_feed` SET `lastUpdate`=?, error=? WHERE id=?'; @@ -453,20 +453,21 @@ SQL; } /** + * Update cached values for selected feeds, or all feeds if no feed ID is provided. * @return int|false */ - public function updateCachedValues(int $id = 0) { + public function updateCachedValues(int ...$feedIds) { //2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE - $sql = 'UPDATE `_feed` ' - . 'SET `cache_nbEntries`=(SELECT COUNT(e1.id) FROM `_entry` e1 WHERE e1.id_feed=`_feed`.id),' - . '`cache_nbUnreads`=(SELECT COUNT(e2.id) FROM `_entry` e2 WHERE e2.id_feed=`_feed`.id AND e2.is_read=0)' - . ($id != 0 ? ' WHERE id=:id' : ''); - $stm = $this->pdo->prepare($sql); - if ($stm !== false && $id != 0) { - $stm->bindParam(':id', $id, PDO::PARAM_INT); + $sql = << 0) { + $sql .= ' WHERE id IN (' . str_repeat('?,', count($feedIds) - 1). '?)'; } - - if ($stm !== false && $stm->execute()) { + $stm = $this->pdo->prepare($sql); + if ($stm !== false && $stm->execute($feedIds)) { return $stm->rowCount(); } else { $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo(); -- cgit v1.2.3