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/FeedDAO.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/FeedDAO.php')
| -rw-r--r-- | app/Models/FeedDAO.php | 23 |
1 files changed, 12 insertions, 11 deletions
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 = <<<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) +SQL; + if (count($feedIds) > 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(); |
