From a14a5985cd29b6cff0afac148c026633a5705479 Mon Sep 17 00:00:00 2001 From: Benjamin Gaussorgues Date: Fri, 29 Nov 2024 15:33:40 +0100 Subject: chore(systemtags): pre-compute user authorizations Signed-off-by: Benjamin Gaussorgues --- apps/dav/lib/SystemTag/SystemTagList.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/dav/lib/SystemTag/SystemTagList.php b/apps/dav/lib/SystemTag/SystemTagList.php index 087c84fabd9..63e69db0eda 100644 --- a/apps/dav/lib/SystemTag/SystemTagList.php +++ b/apps/dav/lib/SystemTag/SystemTagList.php @@ -19,18 +19,20 @@ use Sabre\Xml\Writer; */ class SystemTagList implements Element { public const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; + private array $canAssignTagMap = []; /** * @param ISystemTag[] $tags */ public function __construct( private array $tags, - private ISystemTagManager $tagManager, - private ?IUser $user, + ISystemTagManager $tagManager, + ?IUser $user, ) { $this->tags = $tags; - $this->tagManager = $tagManager; - $this->user = $user; + foreach ($this->tags as $tag) { + $this->canAssignTagMap[$tag->getId()] = $tagManager->canUserAssignTag($tag, $user); + } } /** @@ -48,7 +50,7 @@ class SystemTagList implements Element { foreach ($this->tags as $tag) { $writer->startElement('{' . self::NS_NEXTCLOUD . '}system-tag'); $writer->writeAttributes([ - SystemTagPlugin::CANASSIGN_PROPERTYNAME => $this->tagManager->canUserAssignTag($tag, $this->user) ? 'true' : 'false', + SystemTagPlugin::CANASSIGN_PROPERTYNAME => $this->canAssignTagMap[$tag->getId()] ? 'true' : 'false', SystemTagPlugin::ID_PROPERTYNAME => $tag->getId(), SystemTagPlugin::USERASSIGNABLE_PROPERTYNAME => $tag->isUserAssignable() ? 'true' : 'false', SystemTagPlugin::USERVISIBLE_PROPERTYNAME => $tag->isUserVisible() ? 'true' : 'false', -- cgit v1.2.3