Skip to content

Commit

Permalink
Merge pull request #36941 from nextcloud/bugfix/prevent-error-with-or…
Browse files Browse the repository at this point in the history
…acle-database

Split the comments ids by chunks
  • Loading branch information
nickvergessen authored Mar 3, 2023
2 parents 26e3d51 + e9295f7 commit de64c96
Show file tree
Hide file tree
Showing 2 changed files with 1,223 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/private/Comments/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ public function retrieveAllReactions(int $parentId): array {
->select('message_id')
->from('reactions')
->where($qb->expr()->eq('parent_id', $qb->createNamedParameter($parentId)))
->orderBy('message_id', 'DESC')
->executeQuery();

$commentIds = [];
Expand Down Expand Up @@ -1106,22 +1107,29 @@ private function getCommentsById(array $commentIds): array {
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;
}

Expand Down
Loading

0 comments on commit de64c96

Please sign in to comment.