8000 [Security][Acl] Reduce query size when Select ACL entries for many in… · symfony/symfony@3c3a90b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c3a90b

Browse files
iBiryukovstloyd
authored andcommitted
[Security][Acl] Reduce query size when Select ACL entries for many instances of the same Type at once
1 parent dc4a10e commit 3c3a90b

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

src/Symfony/Component/Security/Acl/Dbal/AclProvider.php

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,47 @@ protected function getAncestorLookupSql(array $batch)
257257
INNER JOIN {$this->options['oid_ancestors_table_name']} a ON a.object_identity_id = o.id
258258
WHERE (
259259
SELECTCLAUSE;
260-
261-
$where = '(o.object_identifier = %s AND c.class_type = %s)';
260+
261+
$types = array();
262262
for ($i=0,$c=count($batch); $i<$c; $i++) {
263-
$sql .= sprintf(
264-
$where,
265-
$this->connection->quote($batch[$i]->getIdentifier()),
266-
$this->connection->quote($batch[$i]->getType())
267-
);
268-
269-
if ($i+1 < $c) {
270-
$sql .= ' OR ';
271-
}
263+
if(!isset($types[$batch[$i]->getType()])) {
264+
$types[$batch[$i]->getType()] = true;
265+
if(count($batch) > 1) {
266+
break;
267+
}
268+
}
272269
}
270+
271+
if(count($types) === 1) {
272+
273+
$where = '(o.object_identifier IN (%s) AND c.class_type = %s)';
274+
$ids = array();
275+
for ($i=0,$c=count($batch); $i<$c; $i++) {
276+
$ids[] = $this->connection->quote($batch[$i]->getIdentifier());
277+
}
278+
279+
$sql .= sprintf(
280+
$where,
281+
implode(',', $ids),
282+
$this->connection->quote($batch[0]->getType())
283+
);
284+
285+
} else {
286+
287+
$where = '(o.object_identifier = %s AND c.class_type = %s)';
288+
for ($i=0,$c=count($batch); $i<$c; $i++) {
289+
$sql .= sprintf(
290+
$where,
291+
$this->connection->quote($batch[$i]->getIdentifier()),
292+
$this->connection->quote($batch[$i]->getType())
293+
);
294+
295+
if ($i+1 < $c) {
296+
$sql .= ' OR ';
297+
}
298+
}
299+
}
300+
273301

274302
$sql .= ')';
275303

@@ -417,7 +445,7 @@ private function doUpdateAceIdentityMap(array &$aces)
417445
* @param array $oidLookup
418446
*
419447
* @return \SplObjectStorage mapping object identities to ACL instances
420-
*
448+
*
421449
* @throws AclNotFoundException
422450
*/
423451
private function lookupObjectIdentities(array $batch, array $sids, array $oidLookup)

0 commit comments

Comments
 (0)
0