Merge pull request #25031 from nextcloud/revert-25020-fix/noid/limitied-allowed-items-db-in

Revert "(LDAP) respect DB limits of arguments in an IN statement"
This commit is contained in:
Roeland Jago Douma 2021-01-08 10:44:48 +01:00 committed by GitHub
commit 84e6e9f7cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 36 deletions

View File

@ -190,30 +190,18 @@ abstract class AbstractMapping {
} }
public function getListOfIdsByDn(array $fdns): array { public function getListOfIdsByDn(array $fdns): array {
$fdnsSlice = count($fdns) > 1000 ? array_slice($fdns, 0, 1000) : $fdns;
$qb = $this->dbc->getQueryBuilder(); $qb = $this->dbc->getQueryBuilder();
$qb->select('owncloud_name', 'ldap_dn') $qb->select('owncloud_name', 'ldap_dn')
->from($this->getTableName(false)) ->from($this->getTableName(false))
->where($qb->expr()->in('ldap_dn', $qb->createNamedParameter($fdnsSlice, QueryBuilder::PARAM_STR_ARRAY))); ->where($qb->expr()->in('ldap_dn', $qb->createNamedParameter($fdns, QueryBuilder::PARAM_STR_ARRAY)));
$slice = 1;
while (isset($fdnsSlice[999])) {
// Oracle does not allow more than 1000 values in the IN list,
// but allows slicing
$fdnsSlice = array_slice($fdns, 1000 * $slice, 1000);
if (!empty($fdnsSlice)) {
$qb->orWhere($qb->expr()->in('ldap_dn', $qb->createNamedParameter($fdnsSlice, QueryBuilder::PARAM_STR_ARRAY)));
}
$slice++;
}
$stmt = $qb->execute(); $stmt = $qb->execute();
$results = [];
while ($entry = $stmt->fetch(\Doctrine\DBAL\FetchMode::ASSOCIATIVE)) { $results = $stmt->fetchAll(\Doctrine\DBAL\FetchMode::ASSOCIATIVE);
foreach ($results as $key => $entry) {
unset($results[$key]);
$results[$entry['ldap_dn']] = $entry['owncloud_name']; $results[$entry['ldap_dn']] = $entry['owncloud_name'];
$this->cache[$entry['ldap_dn']] = $entry['owncloud_name']; $this->cache[$entry['ldap_dn']] = $entry['owncloud_name'];
} }
$stmt->closeCursor();
return $results; return $results;
} }

View File

@ -281,23 +281,4 @@ abstract class AbstractMappingTest extends \Test\TestCase {
$results = $mapper->getList(1, 1); $results = $mapper->getList(1, 1);
$this->assertSame(1, count($results)); $this->assertSame(1, count($results));
} }
public function testGetListOfIdsByDn() {
/** @var AbstractMapping $mapper */
list($mapper,) = $this->initTest();
$listOfDNs = [];
for ($i = 0; $i < 65640; $i++) {
// Postgres has a limit of 65535 values in a single IN list
$name = 'as_' . $i;
$dn = 'uid=' . $name . ',dc=example,dc=org';
$listOfDNs[] = $dn;
if ($i % 20 === 0) {
$mapper->map($dn, $name, 'fake-uuid-' . $i);
}
}
$result = $mapper->getListOfIdsByDn($listOfDNs);
$this->assertSame(65640 / 20, count($result));
}
} }