Crisu83/yii-auth — pull request #77 by kachar (2013-06-11 12:52:42+00:00)
Title: AuthBehavior optimizations to reduce number of queries.

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()`

```php
$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.