From: Côme Chilliet Date: Thu, 7 Sep 2023 15:07:47 +0000 (+0200) Subject: Build query once instead of in-loop X-Git-Tag: v28.0.0beta1~386^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F32912%2Fhead;p=nextcloud-server.git Build query once instead of in-loop Signed-off-by: Côme Chilliet --- diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php index 20e56a03d0a..55792ce1dff 100644 --- a/lib/private/Group/Database.php +++ b/lib/private/Group/Database.php @@ -352,12 +352,13 @@ class Database extends ABackend implements } } - foreach (array_chunk($notFoundGids, 1000) as $chunk) { - $qb = $this->dbConn->getQueryBuilder(); - $result = $qb->select('gid', 'displayname') + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('gid', 'displayname') ->from('groups') - ->where($qb->expr()->in('gid', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY))) - ->executeQuery(); + ->where($qb->expr()->in('gid', $qb->createParameter('ids'))); + foreach (array_chunk($notFoundGids, 1000) as $chunk) { + $qb->setParameter('ids', $chunk, IQueryBuilder::PARAM_STR_ARRAY); + $result = $qb->executeQuery(); while ($row = $result->fetch()) { $this->groupCache[(string)$row['gid']] = [ 'displayname' => (string)$row['displayname'],