Added caching to the loading of system roles

Admin system role was being loaded for each permission check performed.
This caches the fetching for the request lifetime.
This commit is contained in:
Dan Brown 2023-02-23 23:01:03 +00:00
parent a031edec16
commit 8abb41abbd
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9

View File

@ -111,7 +111,13 @@ class Role extends Model implements Loggable
*/
public static function getSystemRole(string $systemName): ?self
{
return static::query()->where('system_name', '=', $systemName)->first();
static $cache = [];
if (!isset($cache[$systemName])) {
$cache[$systemName] = static::query()->where('system_name', '=', $systemName)->first();
}
return $cache[$systemName];
}
/**