Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthBehavior optimizations to reduce number of queries. #77

Merged
merged 3 commits into from
Jun 18, 2013

Conversation

kachar
Copy link
Contributor

@kachar kachar commented Jun 11, 2013

There are two main issues:

The first one is that we get all items and iterate over them to get the relations. This one can be suppressed with a plain query to the items child table and getting just the relations between the items.

The second problem is in the displaying the results table:

Method: AuthItemTypeColumn::renderDataCellContent()

$am = Yii::app()->getAuthManager();
$labelType = $this->active || $am->hasParent($this->itemName, $data['name']) || $am->hasChild($this->itemName, $data['name']) ? 'info' : '';

Here we call hasParent() or hasChild() methods which triggers getItemPermissions() and getAuthItem() methods which queries the database once for each column.(AuthItemTypeColumn, AuthItemRemoveColumn, AuthItemDescriptionColumn). This happens on every row of the result table and leads to poor performance.

If we cache the items and their relations when we get the descendants and ancestors this process gets very clean with limited number of queries.

@crisu83
Copy link
Owner

crisu83 commented Jun 17, 2013

First I'd like to apologize for the late answer, I've been terribly busy lately.

I don't like the naming of the $_itemsGraph property, maybe it could be just $_items or $_itemsCache. Also I don't like the direct accessing of the array in various functions. It would be great if there were a function named getItems or similar that takes the item name as an argument or returns the whole tree if no argument is provided. Could you do these changes and I'll accept this PR.

Thank you in advance.

@kachar
Copy link
Contributor Author

kachar commented Jun 17, 2013

Please review the code. Thanks.

crisu83 added a commit that referenced this pull request Jun 18, 2013
AuthBehavior optimizations to reduce number of queries.
@crisu83 crisu83 merged commit 6532386 into crisu83:master Jun 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants