Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
ACL very slow
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Farah  
View profile  
 More options Apr 16 2012, 7:26 pm
From: Farah <elia...@gmail.com>
Date: Mon, 16 Apr 2012 16:26:28 -0700 (PDT)
Local: Mon, Apr 16 2012 7:26 pm
Subject: ACL very slow

Hi Folks, I need some help about ACL, I'm using *PostgreSql 9.1*, *cakephp
2.1.1*, Acos: 717 rows, Aros: 78, Aros Acos: 1083
Look the number of queries to render the action below:

*(default) 2931 queries took 5398 ms*

I'm using in controller Users/editar

public function editar($id=null)

{              
    $user_id = $id;
    $user_model_name = Configure :: read('acl.aro.user.model');
    $role_model_name = Configure :: read('acl.aro.role.model');

    $user_display_field = $this->AclManager->set_display_name($user_model_name, Configure :: read('acl.user.display_name'));

    $this->set('user_display_field', $user_display_field);

    $role_display_field = $this->AclManager->set_display_name($role_model_name, Configure :: read('acl.aro.role.display_field'));

    $this->set('role_display_field', $role_display_field);

    $this->{$role_model_name}->recursive = -1;
    $roles = $this->{$role_model_name}->find('all', array('order' => $role_display_field, 'contain' => false, 'recursive' => -1));

    $this->{$user_model_name}->recursive = -1;
    $user = $this->{$user_model_name}->read(null, $user_id);

    $permissions = array();
    $methods = array();

    /*
        * Check if the user exists in the ARO table
        */
    $user_aro = $this->Acl->Aro->node($user);
    if (empty($user_aro)) {
        $display_user = $this->{$user_model_name}->find('first', array('conditions' => array($user_model_name . '.id' => $user_id, 'contain' => false, 'recursive' => -1)));
        $this->Session->setFlash(sprintf(__d('acl', "The user '%s' does not exist in the ARO table", true), $display_user[$user_model_name][$user_display_field]), 'flash_error', null, 'plugin_acl');
    } else {
        $actions = $this->AclReflector->get_all_actions();

        foreach ($actions as $full_action) {
            $arr = String::tokenize($full_action, '/');

            if (count($arr) == 2) {
                $plugin_name = null;
                $controller_name = $arr[0];
                $action = $arr[1];
            } elseif (count($arr) == 3) {
                $plugin_name = $arr[0];
                $controller_name = $arr[1];
                $action = $arr[2];
            }

            if (!isset($this->params['named']['ajax'])) {
                $aco_node = $this->Acl->Aco->node($full_action);
                if (!empty($aco_node)) {
                    $authorized = $this->Acl->check($user, $full_action);

                    $permissions[$user[$user_model_name][$this->_get_user_primary_key_name()]] = $authorized ? 1 : 0;
                }
            }

            if (isset($plugin_name)) {
                $methods['plugin'][$plugin_name][$controller_name][] = array('name' => $action, 'permissions' => $permissions);
            } else {
                $methods['app'][$controller_name][] = array('name' => $action, 'permissions' => $permissions);
            }
        }

        /*
            * Check if the user has specific permissions
            */
        $count = $this->Aro->Permission->find('count', array('conditions' => array('Aro.id' => $user_aro[0]['Aro']['id'])));
        if ($count != 0) {
            $this->set('user_has_specific_permissions', true);
        } else {
            $this->set('user_has_specific_permissions', false);
        }
    }

    $this->set('user', $user);
    $this->set('roles', $roles);
    $this->set('actions', $methods);

    if (isset($this->params['named']['ajax'])) {
        $this->render('ajax_user_permissions');
    }
    //Acl Fim        
    $this->set("grupos", $this->Grupo->find("list", array("fields"=>array("Grupo.id","Grupo.grupo"), "order"=>array("Grupo.grupo"),"conditions"=>array("Grupo.ativo"=>true) )));
    $this->set("colaboradores", $this->Colaborador->find("list", array("fields"=>array("Colaborador.id_colab","Colaborador.nome"), "order"=>array("Colaborador.nome"),"conditions"=>array("Colaborador.ativo"= >true) )));

    if(is_numeric($id))
    {
        $this->Usuario->id = $id;

        if(empty($this->request->data))
        {   $this->request->data = $this->Usuario->find("first",array("contain"=>array("Colaborador"),"conditi ons"=>array("Usuario.id"=>$id)));   }
        else
        {  
            if($this->Usuario->save($this->request->data))
            {
                $this->Session->setFlash("Usu&aacute;rio salvo", 'default', array('class' => 'success ui-corner-all'));
                $this->redirect(array("controller"=>"usuarios","action"=>"index"));
            }
            else
            {   $this->Session->setFlash("Erro ao salvar o usu&aacute;rio", 'default', array('class' => 'error ui-corner-all'));   }
        }
    }

}

Any one can help me with this ?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
stork  
View profile  
 More options Apr 17 2012, 7:09 am
From: stork <lubomir.st...@gmail.com>
Date: Tue, 17 Apr 2012 04:09:00 -0700 (PDT)
Subject: Re: ACL very slow

> Any one can help me with this ?

Not me, sorry. This is example, how should NOT look code of CakePHP
application, controller should be as slim as possible.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Farah  
View profile  
 More options Apr 17 2012, 7:41 am
From: Farah <elia...@gmail.com>
Date: Tue, 17 Apr 2012 04:41:12 -0700 (PDT)
Local: Tues, Apr 17 2012 7:41 am
Subject: Re: ACL very slow

Ok, I'm sorry stork, but I if I just try put in the session all permissions
of the controller:

$acoes = $this->Acao->find("all", array("conditions" =>
array("Controller.alias" => $controller)));
            foreach ($acoes as $key => $acao) {
                if (!$this->Session->check("Auth.Permissions." .
$controller . "." . $acao["Acao"]["alias"])) {
                    if ($this->SessionAcl->check(array('model' =>
'Usuario', 'foreign_key' => $this->Auth->user('id')), $controller . "/" .
$acao["Acao"]["alias"])) {
                        $this->Session->write("Auth.Permissions." .
$controller . "." . $acao["Acao"]["alias"], true);
                    }
                }
            }

It takes (default) 561 queries took 1072 ms, the count of $acoes is 7, I
don't understand why 561 queries, is too slow?

Thanks =)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
stork  
View profile  
 More options Apr 17 2012, 8:13 am
From: stork <lubomir.st...@gmail.com>
Date: Tue, 17 Apr 2012 05:13:21 -0700 (PDT)
Local: Tues, Apr 17 2012 8:13 am
Subject: Re: ACL very slow

1. Do you store sessions in database? If yes, is it the same database as
the one with application data? If yes, why? And why not use other
(memcache) storage for sessions?

2. Stop blaming core code for slowness, until you'll be able to write short
example NOT using your own classes like SessionAcl etc in it, especially
not after your example code "snippet" above. I do have advanced imagination
and I'm more then just a bit scared of what and how does your other custom
code, used in your last loop over $acoes, where I even don't know what
$recursive you used and how many associations are queried along.

Set up clean CakePHP installation, connect it to the very same database
like your ACL uses, and run some test code related to your doubts WITHOUT
your own code.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Farah  
View profile  
 More options Apr 17 2012, 9:00 am
From: Farah <elia...@gmail.com>
Date: Tue, 17 Apr 2012 06:00:05 -0700 (PDT)
Local: Tues, Apr 17 2012 9:00 am
Subject: Re: ACL very slow

I'm not expert in CakePHP, but its very clear that the ACL is slow if my
tables database acos, aros and aros_acos over thousand rows.

Just a simple $this->Acl->check() runs over 500 queries and its clear that
its not the acl generate that, it uses the Tree behavior to find the
specific permission.

1. I'm not using database session.
2. There are many articles on the internet talking about that, and I'm not
blaming, I'm just trying to figure out how fast my app can be.

The articles

1. http://www.visuallizard.com/blog/2009/10/19/241
2. http://www.mainelydesign.com/blog/view/speeding-up-cakephp-acl-component
3.
http://phpknight.com/cakephp-acl-controlled-application-slow-performa...

I'll create a component and helper to make this faster as soon as possible
and I'll post it here.

Thanks for your attention =)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
stork  
View profile  
 More options Apr 17 2012, 10:14 am
From: stork <lubomir.st...@gmail.com>
Date: Tue, 17 Apr 2012 07:14:32 -0700 (PDT)
Local: Tues, Apr 17 2012 10:14 am
Subject: Re: ACL very slow
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
stork  
View profile  
 More options Apr 17 2012, 10:16 am
From: stork <lubomir.st...@gmail.com>
Date: Tue, 17 Apr 2012 07:16:49 -0700 (PDT)
Local: Tues, Apr 17 2012 10:16 am
Subject: Re: ACL very slow

Also, check out these projects
http://plugins.cakephp.org/packages?query=acl
if you do not need wheel with some special shape.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jeremyharris  
View profile  
 More options Apr 17 2012, 11:20 am
From: jeremyharris <funeralm...@gmail.com>
Date: Tue, 17 Apr 2012 08:20:05 -0700 (PDT)
Local: Tues, Apr 17 2012 11:20 am
Subject: Re: ACL very slow

It's quite possible you're just missing indexes[1], which would be a huge
performance problem. Also, make sure the engine is innodb.

1:  http://blog.loadsys.com/2008/03/19/cakephp-12-tuning-the-acl-via-mysql/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jeremyharris  
View profile  
 More options Apr 17 2012, 11:21 am
From: jeremyharris <funeralm...@gmail.com>
Date: Tue, 17 Apr 2012 08:21:36 -0700 (PDT)
Local: Tues, Apr 17 2012 11:21 am
Subject: Re: ACL very slow

I realized after posting that the post I referenced assumes MySQL, but the
idea of indexing is relative nonetheless.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Farah  
View profile  
 More options Apr 17 2012, 11:38 am
From: Farah <elia...@gmail.com>
Date: Tue, 17 Apr 2012 08:38:29 -0700 (PDT)
Local: Tues, Apr 17 2012 11:38 am
Subject: Re: ACL very slow

Thanks for the reply!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Farah  
View profile  
 More options Apr 17 2012, 11:39 am
From: Farah <elia...@gmail.com>
Date: Tue, 17 Apr 2012 08:39:00 -0700 (PDT)
Subject: Re: ACL very slow

Yes, all fields has index


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »