Yii2: Cache RBAC assignments

Created on 16 Mar 2015  路  7Comments  路  Source: yiisoft/yii2

Save SELECT * FROM auth_assignment WHERE user_id='...' results in User component property to avoid duplicate DB queries on one page.
See comment here.

rbac enhancement

Most helpful comment

:+1:
I also think this is a major performance issue in some scenarios.
I'm maybe off topic here (sorry), but here is a very simple workaround :

class DbManagerEx extends DbManager
{
    private $_assignments = [];

    public function getAssignments($userId)
    {
        // Avoid multiple queries per request
        if(!isset($this->_assignments[$userId]))
            $this->_assignments[$userId] = parent::getAssignments($userId);
        return $this->_assignments[$userId];
    }

}

All 7 comments

Any thoughts?

I ran into the same issue as well.

:+1:
I also think this is a major performance issue in some scenarios.
I'm maybe off topic here (sorry), but here is a very simple workaround :

class DbManagerEx extends DbManager
{
    private $_assignments = [];

    public function getAssignments($userId)
    {
        // Avoid multiple queries per request
        if(!isset($this->_assignments[$userId]))
            $this->_assignments[$userId] = parent::getAssignments($userId);
        return $this->_assignments[$userId];
    }

}

@samdark did this ever get done?

as I am getting hundreds of

SELECTb.* FROMauth_assignmenta,auth_itembWHERE ((a.item_name=b.name) AND (a.user_id='91')) AND (b.type=1)

On some pages 馃憥

Not yet. Scheduled for next release though.

@samdark ahh ok, any tips how the above problem could be solved in the meantime?

Try using file storage instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schmunk42 picture schmunk42  路  125Comments

dhiman252 picture dhiman252  路  44Comments

alexraputa picture alexraputa  路  53Comments

njasm picture njasm  路  44Comments

schmunk42 picture schmunk42  路  47Comments