From f2557bed9a669406ac8cca783ffcced8128e8749 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 8 May 2021 00:56:06 +0200 Subject: More cases of max SQL variable number (#3586) Follow up of https://github.com/FreshRSS/FreshRSS/pull/3553 --- app/Models/EntryDAO.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'app/Models/EntryDAO.php') diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 9ed1d564d..a95b9a422 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -262,6 +262,15 @@ SQL; return 0; } FreshRSS_UserDAO::touch(); + if (count($ids) > FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER) { + // Split a query with too many variables parameters + $affected = 0; + $idsChunks = array_chunk($ids, FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER, true); + foreach ($idsChunks as $idsChunk) { + $affected += $this->markFavorite($idsChunk, $is_favorite); + } + return $affected; + } $sql = 'UPDATE `_entry` ' . 'SET is_favorite=? ' . 'WHERE id IN (' . str_repeat('?,', count($ids) - 1). '?)'; @@ -344,6 +353,14 @@ SQL; $affected += $this->markRead($id, $is_read); } return $affected; + } elseif (count($ids) > FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER) { + // Split a query with too many variables parameters + $affected = 0; + $idsChunks = array_chunk($ids, FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER, true); + foreach ($idsChunks as $idsChunk) { + $affected += $this->markRead($idsChunk, $is_read); + } + return $affected; } $sql = 'UPDATE `_entry` ' @@ -962,6 +979,15 @@ SQL; public function listByIds($ids, $order = 'DESC') { if (count($ids) < 1) { yield false; + } elseif (count($ids) > FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER) { + // Split a query with too many variables parameters + $idsChunks = array_chunk($ids, FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER, true); + foreach ($idsChunks as $idsChunk) { + foreach ($this->listByIds($idsChunk, $order) as $entry) { + yield $entry; + } + } + return; } $sql = 'SELECT id, guid, title, author, ' @@ -1026,6 +1052,14 @@ SQL; public function updateLastSeen($id_feed, $guids, $mtime = 0) { if (count($guids) < 1) { return 0; + } elseif (count($guids) > FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER) { + // Split a query with too many variables parameters + $affected = 0; + $guidsChunks = array_chunk($guids, FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER, true); + foreach ($guidsChunks as $guidsChunk) { + $affected += $this->updateLastSeen($id_feed, $guidsChunk, $mtime); + } + return $affected; } $sql = 'UPDATE `_entry` SET `lastSeen`=? WHERE id_feed=? AND guid IN (' . str_repeat('?,', count($guids) - 1). '?)'; $stm = $this->pdo->prepare($sql); -- cgit v1.2.3