entrust icon indicating copy to clipboard operation
entrust copied to clipboard

Duplicate query Roles

Open yurikzt opened this issue 7 years ago • 4 comments

Fix, please duplicate query Roles in EntrustUserTrait

protected $roles;

//Big block of caching functionality.
    public function cachedRoles() {
        if ($this->roles instanceof Collection)
            return $this->roles;
        $userPrimaryKey = $this->primaryKey;
        $cacheKey = 'entrust_roles_for_user_' . $this->$userPrimaryKey;
        if (Cache::getStore() instanceof TaggableStore) {
            return $this->roles = Cache::tags(Config::get('entrust.role_user_table'))->remember($cacheKey, Config::get('cache.ttl'), function () {
                return $this->roles()->get();
            });
        } else
            return $this->roles = $this->roles()->get();
    }

yurikzt avatar Apr 25 '17 09:04 yurikzt

Add to file EntrustUserTrait and EntrustRoleTrait

use Illuminate\Database\Eloquent\Collection;

and for EntrustRoleTrait

protected $perms;

//Big block of caching functionality.
public function cachedPermissions()
{
    if ($this->perms instanceof Collection) {
        return $this->perms;
    }
    $rolePrimaryKey = $this->primaryKey;
    $cacheKey = 'entrust_permissions_for_role_' . $this->$rolePrimaryKey;
    if (Cache::getStore() instanceof TaggableStore) {
    //    return Cache::store('array')->tags(Config::get('entrust.permission_role_table'))->remember($cacheKey, Config::get('entrust.cache.ttl', 60), function () {
        return Cache::tags(Config::get('entrust.permission_role_table'))->remember($cacheKey, Config::get('entrust.cache_ttl', 60), function () {
            return $this->perms()->get();
        });
    } else {
        return $this->perms = $this->perms()->get();
    }
}

rudashi avatar May 09 '17 10:05 rudashi

set: CACHE_DRIVER=array in .env file

and add 'ttl' in confg/cache.php

return [
/***/
    'ttl' => 60,
/***/
];

tatarysh avatar Nov 01 '18 11:11 tatarysh

@karnasoneji wrong place.

image

Don't forget to clear cache config.

tatarysh avatar Jan 23 '21 07:01 tatarysh

thanks @tatarysh 👍

karnasoneji avatar Jan 25 '21 01:01 karnasoneji