aboutsummaryrefslogtreecommitdiff
path: root/app/Models/EntryDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2021-05-08 00:56:06 +0200
committerGravatar GitHub <noreply@github.com> 2021-05-08 00:56:06 +0200
commitf2557bed9a669406ac8cca783ffcced8128e8749 (patch)
treeecbdd97d042fed717cf23c6bee6a52d18d1dba5f /app/Models/EntryDAO.php
parenta65097f1b334ddd4da69343745324a93b6a754c6 (diff)
More cases of max SQL variable number (#3586)
Follow up of https://github.com/FreshRSS/FreshRSS/pull/3553
Diffstat (limited to 'app/Models/EntryDAO.php')
-rw-r--r--app/Models/EntryDAO.php34
1 files changed, 34 insertions, 0 deletions
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);