From 6951c4ef56c26c03851ee986834558622768dea9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Mar 2021 08:49:23 +0100 Subject: [PATCH] Chunk the array of phone numbers Signed-off-by: Joas Schilling --- lib/private/Accounts/AccountManager.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 05feaf87b8..c5a0f21319 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -229,19 +229,23 @@ class AccountManager implements IAccountManager { } public function searchUsers(string $property, array $values): array { + $chunks = array_chunk($values, 500); $query = $this->connection->getQueryBuilder(); $query->select('*') ->from($this->dataTable) ->where($query->expr()->eq('name', $query->createNamedParameter($property))) - ->andWhere($query->expr()->in('value', $query->createNamedParameter($values, IQueryBuilder::PARAM_STR_ARRAY))); + ->andWhere($query->expr()->in('value', $query->createParameter('values'))); - $result = $query->execute(); $matches = []; + foreach ($chunks as $chunk) { + $query->setParameter('values', $chunk, IQueryBuilder::PARAM_STR_ARRAY); + $result = $query->execute(); - while ($row = $result->fetch()) { - $matches[$row['value']] = $row['uid']; + while ($row = $result->fetch()) { + $matches[$row['value']] = $row['uid']; + } + $result->closeCursor(); } - $result->closeCursor(); return $matches; }