Merge pull request #26084 from nextcloud/backport/26079/stable21

[stable21] Chunk the array of phone numbers
This commit is contained in:
Roeland Jago Douma 2021-03-12 12:44:25 +01:00 committed by GitHub
commit 3ac6dc3b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -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;
}

View File

@ -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;