Merge pull request #27187 from Simounet/fix/comments-query-oracle-limit-compliance
Fix Oracle query limit compliance in Comments
This commit is contained in:
commit
fb7899135e
|
@ -634,6 +634,7 @@ class Manager implements ICommentsManager {
|
||||||
* @since 21.0.0
|
* @since 21.0.0
|
||||||
*/
|
*/
|
||||||
public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array {
|
public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array {
|
||||||
|
$unreadComments = [];
|
||||||
$query = $this->dbConn->getQueryBuilder();
|
$query = $this->dbConn->getQueryBuilder();
|
||||||
$query->select('c.object_id', $query->func()->count('c.id', 'num_comments'))
|
$query->select('c.object_id', $query->func()->count('c.id', 'num_comments'))
|
||||||
->from('comments', 'c')
|
->from('comments', 'c')
|
||||||
|
@ -643,7 +644,7 @@ class Manager implements ICommentsManager {
|
||||||
$query->expr()->eq('c.object_id', 'm.object_id')
|
$query->expr()->eq('c.object_id', 'm.object_id')
|
||||||
))
|
))
|
||||||
->where($query->expr()->eq('c.object_type', $query->createNamedParameter($objectType)))
|
->where($query->expr()->eq('c.object_type', $query->createNamedParameter($objectType)))
|
||||||
->andWhere($query->expr()->in('c.object_id', $query->createNamedParameter($objectIds, IQueryBuilder::PARAM_STR_ARRAY)))
|
->andWhere($query->expr()->in('c.object_id', $query->createParameter('ids')))
|
||||||
->andWhere($query->expr()->orX(
|
->andWhere($query->expr()->orX(
|
||||||
$query->expr()->gt('c.creation_timestamp', 'm.marker_datetime'),
|
$query->expr()->gt('c.creation_timestamp', 'm.marker_datetime'),
|
||||||
$query->expr()->isNull('m.marker_datetime')
|
$query->expr()->isNull('m.marker_datetime')
|
||||||
|
@ -654,10 +655,14 @@ class Manager implements ICommentsManager {
|
||||||
$query->andWhere($query->expr()->eq('c.verb', $query->createNamedParameter($verb)));
|
$query->andWhere($query->expr()->eq('c.verb', $query->createNamedParameter($verb)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $query->execute();
|
foreach (array_chunk($objectIds, 1000) as $chunk) {
|
||||||
$unreadComments = array_fill_keys($objectIds, 0);
|
$query->setParameter('ids', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
|
||||||
while ($row = $result->fetch()) {
|
$result = $query->execute();
|
||||||
$unreadComments[$row['object_id']] = (int) $row['num_comments'];
|
|
||||||
|
$unreadComments += array_fill_keys($objectIds, 0);
|
||||||
|
while ($row = $result->fetch()) {
|
||||||
|
$unreadComments[$row['object_id']] = (int) $row['num_comments'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$result->closeCursor();
|
$result->closeCursor();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue