Merge pull request #26079 from nextcloud/bugfix/noid/chunk-phone-search
Chunk the array of phone numbers
This commit is contained in:
commit
7ac6eee129
|
@ -229,19 +229,23 @@ class AccountManager implements IAccountManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchUsers(string $property, array $values): array {
|
public function searchUsers(string $property, array $values): array {
|
||||||
|
$chunks = array_chunk($values, 500);
|
||||||
$query = $this->connection->getQueryBuilder();
|
$query = $this->connection->getQueryBuilder();
|
||||||
$query->select('*')
|
$query->select('*')
|
||||||
->from($this->dataTable)
|
->from($this->dataTable)
|
||||||
->where($query->expr()->eq('name', $query->createNamedParameter($property)))
|
->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 = [];
|
$matches = [];
|
||||||
|
foreach ($chunks as $chunk) {
|
||||||
|
$query->setParameter('values', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
|
||||||
|
$result = $query->execute();
|
||||||
|
|
||||||
while ($row = $result->fetch()) {
|
while ($row = $result->fetch()) {
|
||||||
$matches[$row['value']] = $row['uid'];
|
$matches[$row['value']] = $row['uid'];
|
||||||
|
}
|
||||||
|
$result->closeCursor();
|
||||||
}
|
}
|
||||||
$result->closeCursor();
|
|
||||||
|
|
||||||
return $matches;
|
return $matches;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,12 @@ use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountsManagerTest
|
* Class AccountManagerTest
|
||||||
*
|
*
|
||||||
* @group DB
|
* @group DB
|
||||||
* @package Test\Accounts
|
* @package Test\Accounts
|
||||||
*/
|
*/
|
||||||
class AccountsManagerTest extends TestCase {
|
class AccountManagerTest extends TestCase {
|
||||||
|
|
||||||
/** @var \OCP\IDBConnection */
|
/** @var \OCP\IDBConnection */
|
||||||
private $connection;
|
private $connection;
|
Loading…
Reference in New Issue