From 822feb2497c20040d9cf5f9b6e18ee91a56f424a Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 16 Jun 2015 17:18:02 +0930 Subject: [PATCH] Cache user permissions between calls --- framework/core/src/Core/Models/User.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Core/Models/User.php b/framework/core/src/Core/Models/User.php index c9d9f8972..902c11013 100755 --- a/framework/core/src/Core/Models/User.php +++ b/framework/core/src/Core/Models/User.php @@ -311,9 +311,13 @@ class User extends Model return true; } - $count = $this->permissions()->where('permission', $permission)->count(); + static $permissions; - return (bool) $count; + if (!$permissions) { + $permissions = $this->permissions()->get(); + } + + return (bool) $permissions->contains('permission', $permission); } public function getUnreadNotificationsCount()