diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2021-03-12 12:44:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-12 12:44:25 +0100 |
commit | 3ac6dc3b50ed710b6518552dbefaa39095dac79e (patch) | |
tree | aa43c360bde503e4e63b2f64a0b18dcd7ceb11a8 | |
parent | 6e2f7ddc7ae031d52853943c2f5fa46e85681892 (diff) | |
parent | 2d92f1117b43c0d2e8e30dbc90380d5b364a12a6 (diff) | |
download | nextcloud-server-3ac6dc3b50ed710b6518552dbefaa39095dac79e.tar.gz nextcloud-server-3ac6dc3b50ed710b6518552dbefaa39095dac79e.zip |
Merge pull request #26084 from nextcloud/backport/26079/stable21
[stable21] Chunk the array of phone numbers
-rw-r--r-- | lib/private/Accounts/AccountManager.php | 14 | ||||
-rw-r--r-- | tests/lib/Accounts/AccountManagerTest.php (renamed from tests/lib/Accounts/AccountsManagerTest.php) | 4 |
2 files changed, 11 insertions, 7 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 05feaf87b8f..c5a0f21319e 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; } diff --git a/tests/lib/Accounts/AccountsManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php index d13d5f4186a..fcd1a78add7 100644 --- a/tests/lib/Accounts/AccountsManagerTest.php +++ b/tests/lib/Accounts/AccountManagerTest.php @@ -34,12 +34,12 @@ use Symfony\Component\EventDispatcher\GenericEvent; use Test\TestCase; /** - * Class AccountsManagerTest + * Class AccountManagerTest * * @group DB * @package Test\Accounts */ -class AccountsManagerTest extends TestCase { +class AccountManagerTest extends TestCase { /** @var \OCP\IDBConnection */ private $connection; |