From d4ea088cd2d557e8fe7c87174ddc630d03d10b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 20 Jun 2024 08:31:00 +0200 Subject: [PATCH] perf: Avoid fetching labels and owner details on permission check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/CardMapper.php | 10 ++++++---- lib/Service/PermissionService.php | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Db/CardMapper.php b/lib/Db/CardMapper.php index 2132da4ed..f1d2d34c1 100644 --- a/lib/Db/CardMapper.php +++ b/lib/Db/CardMapper.php @@ -113,7 +113,7 @@ public function markNotified(Card $card): Entity { return parent::update($cardUpdate); } - public function find($id): Card { + public function find($id, bool $enhance = true): Card { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from('deck_cards') @@ -122,9 +122,11 @@ public function find($id): Card { ->addOrderBy('id'); /** @var Card $card */ $card = $this->findEntity($qb); - $labels = $this->labelMapper->findAssignedLabelsForCard($card->getId()); - $card->setLabels($labels); - $this->mapOwner($card); + if ($enhance) { + $labels = $this->labelMapper->findAssignedLabelsForCard($card->getId()); + $card->setLabels($labels); + $this->mapOwner($card); + } return $card; } diff --git a/lib/Service/PermissionService.php b/lib/Service/PermissionService.php index c43ea54ae..eec3474c3 100644 --- a/lib/Service/PermissionService.php +++ b/lib/Service/PermissionService.php @@ -119,7 +119,7 @@ public function checkPermission(?IPermissionMapper $mapper, $id, int $permission if ($permissions[$permission] === true) { if (!$allowDeletedCard && $mapper instanceof CardMapper) { - $card = $mapper->find((int)$id); + $card = $mapper->find((int)$id, false); if ($card->getDeletedAt() > 0) { throw new NoPermissionException('Card is deleted'); }