Add cache policy for ServerPolicy
10 second cache, just long enough to handle the page load without making more than one MySQL call.
This commit is contained in:
parent
f91e4c511e
commit
efdc3e6fd8
2 changed files with 13 additions and 1 deletions
|
@ -24,11 +24,14 @@
|
|||
|
||||
namespace Pterodactyl\Policies;
|
||||
|
||||
use Cache;
|
||||
use Carbon;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Models\Server;
|
||||
|
||||
class ServerPolicy
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
|
@ -53,7 +56,13 @@ class ServerPolicy
|
|||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission($permission)->exists();
|
||||
$permissions = Cache::remember('ServerPolicy.' . $user->uuid . $server->uuid, Carbon::now()->addSeconds(10), function () use ($user, $server) {
|
||||
return $user->permissions()->server($server)->get()->transform(function ($item) {
|
||||
return $item->permission;
|
||||
})->values();
|
||||
});
|
||||
|
||||
return ($permissions->search($permission, true) !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue