Skip to content

Commit

Permalink
Merge pull request #26084 from nextcloud/backport/26079/stable21
Browse files Browse the repository at this point in the history
[stable21] Chunk the array of phone numbers
  • Loading branch information
rullzer authored Mar 12, 2021
2 parents 6e2f7dd + 2d92f11 commit 3ac6dc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,23 @@ public function getUser(IUser $user) {
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
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;
Expand Down

0 comments on commit 3ac6dc3

Please sign in to comment.