diff --git a/lib/Service/PermissionService.php b/lib/Service/PermissionService.php index b7e525c44..06a6da62d 100644 --- a/lib/Service/PermissionService.php +++ b/lib/Service/PermissionService.php @@ -33,7 +33,6 @@ use OCA\Deck\Db\IPermissionMapper; use OCA\Deck\Db\User; use OCA\Deck\NoPermissionException; use OCP\AppFramework\Db\DoesNotExistException; -use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\IConfig; use OCP\IGroupManager; @@ -65,6 +64,7 @@ class PermissionService { private $users = []; private $boardCache; + private $permissionCache; public function __construct( ILogger $logger, @@ -88,6 +88,7 @@ class PermissionService { $this->userId = $userId; $this->boardCache = new CappedMemoryCache(); + $this->permissionCache = new CappedMemoryCache(); } /** @@ -97,15 +98,21 @@ class PermissionService { * @return bool|array */ public function getPermissions($boardId) { + if ($cached = $this->permissionCache->get($boardId)) { + return $cached; + } + $owner = $this->userIsBoardOwner($boardId); $acls = $this->aclMapper->findAll($boardId); - return [ + $permissions = [ Acl::PERMISSION_READ => $owner || $this->userCan($acls, Acl::PERMISSION_READ), Acl::PERMISSION_EDIT => $owner || $this->userCan($acls, Acl::PERMISSION_EDIT), Acl::PERMISSION_MANAGE => $owner || $this->userCan($acls, Acl::PERMISSION_MANAGE), Acl::PERMISSION_SHARE => ($owner || $this->userCan($acls, Acl::PERMISSION_SHARE)) && (!$this->shareManager->sharingDisabledForUser($this->userId)) ]; + $this->permissionCache->set($boardId, $permissions); + return $permissions; } /** @@ -343,5 +350,6 @@ class PermissionService { */ public function setUserId(string $userId): void { $this->userId = $userId; + $this->permissionCache->clear(); } }