From: Dan Brown Date: Thu, 23 Feb 2023 23:01:03 +0000 (+0000) Subject: Added caching to the loading of system roles X-Git-Tag: v23.02~1^2~4 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/8abb41abbd5833217823890da936a29a129bd046 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. --- diff --git a/app/Auth/Role.php b/app/Auth/Role.php index d6c4a0951..8f9702fa0 100644 --- a/app/Auth/Role.php +++ b/app/Auth/Role.php @@ -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]; } /**