Skip to content

Commit

Permalink
perf: Avoid fetching labels and owner details on permission check
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Jun 25, 2024
1 parent ea4655b commit d4ea088
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/Db/CardMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PermissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit d4ea088

Please sign in to comment.