Merge pull request #36941 from nextcloud/bugfix/prevent-error-with-oracle-database

Split the comments ids by chunks
pull/37040/head
Joas Schilling 3 years ago committed by GitHub
commit de64c96a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      lib/private/Comments/Manager.php
  2. 1207
      tests/lib/Comments/ManagerTest.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;
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save