summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Biryukov <ilya@goparty.ie>2012-12-25 22:46:10 +0000
committerJoseph Bielawski <stloyd@gmail.com>2013-01-07 09:54:34 +0100
commit250002e984d8544034666516760c3863c8bc4001 (patch)
treea87e4a651e74e17845ef30a9f3de027920bd3e1a
parentb11eb9120cde5e05fccc39fdeef7fadf0fb4fa4d (diff)
downloadsymfony-security-250002e984d8544034666516760c3863c8bc4001.zip
symfony-security-250002e984d8544034666516760c3863c8bc4001.tar.gz
symfony-security-250002e984d8544034666516760c3863c8bc4001.tar.bz2
[Security][Acl] Reduce query size when Select ACL entries for many instances of the same Type at once
-rw-r--r--Acl/Dbal/AclProvider.php52
1 files changed, 40 insertions, 12 deletions
diff --git a/Acl/Dbal/AclProvider.php b/Acl/Dbal/AclProvider.php
index 1b6eb0a..55d7bd7 100644
--- a/Acl/Dbal/AclProvider.php
+++ b/Acl/Dbal/AclProvider.php
@@ -257,19 +257,47 @@ SELECTCLAUSE;
INNER JOIN {$this->options['oid_ancestors_table_name']} a ON a.object_identity_id = o.id
WHERE (
SELECTCLAUSE;
-
- $where = '(o.object_identifier = %s AND c.class_type = %s)';
+
+ $types = array();
for ($i=0,$c=count($batch); $i<$c; $i++) {
- $sql .= sprintf(
- $where,
- $this->connection->quote($batch[$i]->getIdentifier()),
- $this->connection->quote($batch[$i]->getType())
- );
-
- if ($i+1 < $c) {
- $sql .= ' OR ';
- }
+ if(!isset($types[$batch[$i]->getType()])) {
+ $types[$batch[$i]->getType()] = true;
+ if(count($batch) > 1) {
+ break;
+ }
+ }
}
+
+ if(count($types) === 1) {
+
+ $where = '(o.object_identifier IN (%s) AND c.class_type = %s)';
+ $ids = array();
+ for ($i=0,$c=count($batch); $i<$c; $i++) {
+ $ids[] = $this->connection->quote($batch[$i]->getIdentifier());
+ }
+
+ $sql .= sprintf(
+ $where,
+ implode(',', $ids),
+ $this->connection->quote($batch[0]->getType())
+ );
+
+ } else {
+
+ $where = '(o.object_identifier = %s AND c.class_type = %s)';
+ for ($i=0,$c=count($batch); $i<$c; $i++) {
+ $sql .= sprintf(
+ $where,
+ $this->connection->quote($batch[$i]->getIdentifier()),
+ $this->connection->quote($batch[$i]->getType())
+ );
+
+ if ($i+1 < $c) {
+ $sql .= ' OR ';
+ }
+ }
+ }
+
$sql .= ')';
@@ -417,7 +445,7 @@ QUERY;
* @param array $oidLookup
*
* @return \SplObjectStorage mapping object identities to ACL instances
- *
+ *
* @throws AclNotFoundException
*/
private function lookupObjectIdentities(array $batch, array $sids, array $oidLookup)