From 72bc2f438a68cf96cad8318783f9edb7a11c9a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 16 Aug 2022 16:06:40 +0200 Subject: [PATCH 1/2] Use capped memory cache for board permissions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/PermissionService.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Service/PermissionService.php b/lib/Service/PermissionService.php index b7e525c44..d0630a633 100644 --- a/lib/Service/PermissionService.php +++ b/lib/Service/PermissionService.php @@ -23,7 +23,7 @@ namespace OCA\Deck\Service; -use OC\Cache\CappedMemoryCache; +use OCP\Cache\CappedMemoryCache; use OCA\Circles\Model\Member; use OCA\Deck\Db\Acl; use OCA\Deck\Db\AclMapper; @@ -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; @@ -64,7 +63,8 @@ class PermissionService { /** @var array */ private $users = []; - private $boardCache; + private CappedMemoryCache $boardCache; + private CappedMemoryCache $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(); } } From 8ace53bfe20b1eee73de8a372e9b5d64598f9bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 26 Aug 2022 10:06:09 +0200 Subject: [PATCH 2/2] Make CappedMemoryCache usage compatible with older releases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/PermissionService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Service/PermissionService.php b/lib/Service/PermissionService.php index d0630a633..06a6da62d 100644 --- a/lib/Service/PermissionService.php +++ b/lib/Service/PermissionService.php @@ -23,7 +23,7 @@ namespace OCA\Deck\Service; -use OCP\Cache\CappedMemoryCache; +use OC\Cache\CappedMemoryCache; use OCA\Circles\Model\Member; use OCA\Deck\Db\Acl; use OCA\Deck\Db\AclMapper; @@ -63,8 +63,8 @@ class PermissionService { /** @var array */ private $users = []; - private CappedMemoryCache $boardCache; - private CappedMemoryCache $permissionCache; + private $boardCache; + private $permissionCache; public function __construct( ILogger $logger,