8000 merged branch stloyd/feature/acl_query (PR #6597) · symfony/symfony@1e62588 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e62588

Browse files
committed
merged branch stloyd/feature/acl_query (PR #6597)
This PR was merged into the master branch. Commits ------- d570dbe [Security][Acl] CS fix for commit: 3c3a90b 3c3a90b [Security][Acl] Reduce query size when Select ACL entries for many instances of the same Type at once Discussion ---------- [Security][Acl] Reduce query size when select ACL type is same Rebased & squashed version of #6479. ps. I was thinking that this could be done on _lower_ versions too, but was not sure =)
2 parents dc4a10e + d570dbe commit 1e62588

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,40 @@ protected function getAncestorLookupSql(array $batch)
258258
WHERE (
259259
SELECTCLAUSE;
260260

261-
$where = '(o.object_identifier = %s AND c.class_type = %s)';
262-
for ($i=0,$c=count($batch); $i<$c; $i++) {
261+
$types = array();
262+
$count = count($batch);
263+
for ($i = 0; $i < $count; $i++) {
264+
if (!isset($types[$batch[$i]->getType()])) {
265+
$types[$batch[$i]->getType()] = true;
266+
if ($count > 1) {
267+
break;
268+
}
269+
}
270+
}
271+
272+
if (1 === count($types)) {
273+
$ids = array();
274+
for ($i = 0; $i < $count; $i++) {
275+
$ids[] = $this->connection->quote($batch[$i]->getIdentifier());
276+
}
277+
263278
$sql .= sprintf(
264-
$where,
265-
$this->connection->quote($batch[$i]->getIdentifier()),
266-
$this->connection->quote($batch[$i]->getType())
279+
'(o.object_identifier IN (%s) AND c.class_type = %s)',
280+
implode(',', $ids),
281+
$this->connection->quote($batch[0]->getType())
267282
);
268-
269-
if ($i+1 < $c) {
270-
$sql .= ' OR ';
283+
} else {
284+
$where = '(o.object_identifier = %s AND c.class_type = %s)';
285+
for ($i = 0; $i < $count; $i++) {
286+
$sql .= sprintf(
287+
$where,
288+
$this->connection->quote($batch[$i]->getIdentifier()),
289+
$this->connection->quote($batch[$i]->getType())
290+
);
291+
292+
if ($i+1 < $count) {
293+
$sql .= ' OR ';
294+
}
271295
}
272296
}
273297

0 commit comments

Comments
 (0)
0