Skip to content

Commit 8abb41a

Browse files
committed
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.
1 parent a031ede commit 8abb41a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/Auth/Role.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@ public static function getRole(string $displayName): ?self
111111
*/
112112
public static function getSystemRole(string $systemName): ?self
113113
{
114-
return static::query()->where('system_name', '=', $systemName)->first();
114+
static $cache = [];
115+
116+
if (!isset($cache[$systemName])) {
117+
$cache[$systemName] = static::query()->where('system_name', '=', $systemName)->first();
118+
}
119+
120+
return $cache[$systemName];
115121
}
116122

117123
/**

0 commit comments

Comments
 (0)