Skip to content

Commit

Permalink
Added caching to the loading of system roles
Browse files Browse the repository at this point in the history
Admin system role was being loaded for each permission check performed.
This caches the fetching for the request lifetime.
  • Loading branch information
ssddanbrown committed Feb 23, 2023
1 parent a031ede commit 8abb41a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/Auth/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ public static function getRole(string $displayName): ?self
*/
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];
}

/**
Expand Down

0 comments on commit 8abb41a

Please sign in to comment.