Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix Oracle query limit compliance in Comments
Signed-off-by: Simounet <[email protected]>
  • Loading branch information
Simounet authored and szaimen committed Sep 23, 2021
commit f325a4ae60de112a8449faf33f62a916bbcdea28
15 changes: 10 additions & 5 deletions lib/private/Comments/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $
* @since 21.0.0
*/
public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array {
$unreadComments = [];
$query = $this->dbConn->getQueryBuilder();
$query->select('c.object_id', $query->func()->count('c.id', 'num_comments'))
->from('comments', 'c')
Expand All @@ -642,7 +643,7 @@ public function getNumberOfUnreadCommentsForObjects(string $objectType, array $o
$query->expr()->eq('c.object_id', 'm.object_id')
))
->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(
$query->expr()->gt('c.creation_timestamp', 'm.marker_datetime'),
$query->expr()->isNull('m.marker_datetime')
Expand All @@ -653,10 +654,14 @@ public function getNumberOfUnreadCommentsForObjects(string $objectType, array $o
$query->andWhere($query->expr()->eq('c.verb', $query->createNamedParameter($verb)));
}

$result = $query->execute();
$unreadComments = array_fill_keys($objectIds, 0);
while ($row = $result->fetch()) {
$unreadComments[$row['object_id']] = (int) $row['num_comments'];
foreach (array_chunk($objectIds, 1000) as $chunk) {
$query->setParameter('ids', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$result = $query->execute();

$unreadComments += array_fill_keys($objectIds, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this uses $objectIds instead of $chunk it would have been enough to do it once before the loop even starts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Do you want me to make a new PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can fix it here and do a new PR for master only

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let me know if I can do anything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, master PR in #27316

while ($row = $result->fetch()) {
$unreadComments[$row['object_id']] = (int) $row['num_comments'];
}
}
$result->closeCursor();

Expand Down