improving acl perfomance

This commit is contained in:
Anatoliy Petrovskiy 2014-06-23 13:51:52 +03:00
parent bb15271622
commit ad678e3988
2 changed files with 9 additions and 9 deletions

View file

@ -58,8 +58,8 @@ class DbAclSchema extends CakeSchema {
'rght' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10), 'rght' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
'indexes' => array( 'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1), 'PRIMARY' => array('column' => 'id', 'unique' => 1),
'idx_acos_lft_rght' => array('column' => array('lft', 'rght'),'unique' => 0), 'idx_acos_lft_rght' => array('column' => array('lft', 'rght'), 'unique' => 0),
'idx_acos_alias' => array('column' => 'alias','unique' => 0) 'idx_acos_alias' => array('column' => 'alias', 'unique' => 0)
) )
); );
@ -76,8 +76,8 @@ class DbAclSchema extends CakeSchema {
'rght' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10), 'rght' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
'indexes' => array( 'indexes' => array(
'PRIMARY' => array('column' => 'id','unique' => 1), 'PRIMARY' => array('column' => 'id','unique' => 1),
'idx_aros_lft_rght' => array('column' => array('lft', 'rght'),'unique' => 0), 'idx_aros_lft_rght' => array('column' => array('lft', 'rght'), 'unique' => 0),
'idx_aros_alias' => array('column' => 'alias','unique' => 0) 'idx_aros_alias' => array('column' => 'alias', 'unique' => 0)
) )
); );

View file

@ -90,7 +90,7 @@ class AclNode extends Model {
'order' => $db->name("{$type}.lft") . ' DESC' 'order' => $db->name("{$type}.lft") . ' DESC'
); );
$conditions_after_join = array(); $conditionsAfterJoin = array();
foreach ($path as $i => $alias) { foreach ($path as $i => $alias) {
$j = $i - 1; $j = $i - 1;
@ -105,9 +105,9 @@ class AclNode extends Model {
); );
// it will be better if this conditions will performs after join operation // it will be better if this conditions will performs after join operation
$conditions_after_join[] = $db->name("{$type}{$j}.id") . ' = ' . $db->name("{$type}{$i}.parent_id"); $conditionsAfterJoin[] = $db->name("{$type}{$j}.id") . ' = ' . $db->name("{$type}{$i}.parent_id");
$conditions_after_join[] = $db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"); $conditionsAfterJoin[] = $db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght");
$conditions_after_join[] = $db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"); $conditionsAfterJoin[] = $db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft");
$queryData['conditions'] = array('or' => array( $queryData['conditions'] = array('or' => array(
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght"), $db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght"),
@ -115,7 +115,7 @@ class AclNode extends Model {
); );
} }
$queryData['conditions'] = array_merge($queryData['conditions'], $conditions_after_join); $queryData['conditions'] = array_merge($queryData['conditions'], $conditionsAfterJoin);
$result = $db->read($this, $queryData, -1); $result = $db->read($this, $queryData, -1);
$path = array_values($path); $path = array_values($path);