Skip to content

Commit

Permalink
Centralize permission caching (#2832)
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 authored May 4, 2021
1 parent 3a6b884 commit 7d4bd8a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,7 @@ public function hasPermission($permission)
return true;
}

if (is_null($this->permissions)) {
$this->permissions = $this->getPermissions();
}

return in_array($permission, $this->permissions);
return in_array($permission, $this->getPermissions());
}

/**
Expand All @@ -399,11 +395,7 @@ public function hasPermissionLike($match)
return true;
}

if (is_null($this->permissions)) {
$this->permissions = $this->getPermissions();
}

foreach ($this->permissions as $permission) {
foreach ($this->getPermissions() as $permission) {
if (substr($permission, -strlen($match)) === $match) {
return true;
}
Expand Down Expand Up @@ -739,7 +731,11 @@ public function permissions()
*/
public function getPermissions()
{
return $this->permissions()->pluck('permission')->all();
if (is_null($this->permissions)) {
$this->permissions = $this->permissions()->pluck('permission')->all();
}

return $this->permissions;
}

/**
Expand Down

0 comments on commit 7d4bd8a

Please sign in to comment.