diff options
author | Vitor Mattos <vitor@php.rio> | 2023-03-01 13:01:25 -0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2023-03-01 13:08:17 -0300 |
commit | e9295f739e2efab4ddd066ed7ce7ce34f6bb7461 (patch) | |
tree | dcebaab6a36dfc12f0aa5907c8f44a1061b1c8b1 /lib/private/Comments/Manager.php | |
parent | 416efc12d6a0e535468082dfb9f88c17b7050236 (diff) | |
download | nextcloud-server-e9295f739e2efab4ddd066ed7ce7ce34f6bb7461.tar.gz nextcloud-server-e9295f739e2efab4ddd066ed7ce7ce34f6bb7461.zip |
Split the comments ids by chunks
Split the comments ids by chunks to prevent error with Oracle database
that can't do a query with more than 1000 parameters.
https://github.com/nextcloud/spreed/issues/8287
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'lib/private/Comments/Manager.php')
-rw-r--r-- | lib/private/Comments/Manager.php | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 00cf323bfbf..c5fb4ebfe34 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -1031,6 +1031,7 @@ class Manager implements ICommentsManager { ->select('message_id') ->from('reactions') ->where($qb->expr()->eq('parent_id', $qb->createNamedParameter($parentId))) + ->orderBy('message_id', 'DESC') ->executeQuery(); $commentIds = []; @@ -1106,22 +1107,29 @@ class Manager implements ICommentsManager { if (!$commentIds) { return []; } - $query = $this->dbConn->getQueryBuilder(); + $chunks = array_chunk($commentIds, 500); + + $query = $this->dbConn->getQueryBuilder(); $query->select('*') ->from('comments') - ->where($query->expr()->in('id', $query->createNamedParameter($commentIds, IQueryBuilder::PARAM_STR_ARRAY))) + ->where($query->expr()->in('id', $query->createParameter('ids'))) ->orderBy('creation_timestamp', 'DESC') ->addOrderBy('id', 'DESC'); $comments = []; - $result = $query->executeQuery(); - while ($data = $result->fetch()) { - $comment = $this->getCommentFromData($data); - $this->cache($comment); - $comments[] = $comment; + foreach ($chunks as $ids) { + $query->setParameter('ids', $ids, IQueryBuilder::PARAM_STR_ARRAY); + + $result = $query->executeQuery(); + while ($data = $result->fetch()) { + $comment = $this->getCommentFromData($data); + $this->cache($comment); + $comments[] = $comment; + } + $result->closeCursor(); } - $result->closeCursor(); + return $comments; } |