perf: remove duplicate fetching of assignments

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2023-02-15 16:43:32 +01:00
parent 133e3f3140
commit c01e542044
2 changed files with 6 additions and 6 deletions

View File

@@ -148,8 +148,8 @@ class CardService {
$cardLabels = array_filter($assignedLabels, function (Label $label) use ($card) { $cardLabels = array_filter($assignedLabels, function (Label $label) use ($card) {
return $label->getCardId() === $card->getId(); return $label->getCardId() === $card->getId();
}); });
$cardAssignedUsers = array_filter($assignedUsers, function (Assignment $label) use ($card) { $cardAssignedUsers = array_filter($assignedUsers, function (Assignment $assignment) use ($card) {
return $label->getCardId() === $card->getId(); return $assignment->getCardId() === $card->getId();
}); });
$card->setLabels($cardLabels); $card->setLabels($cardLabels);
$card->setAssignedUsers($cardAssignedUsers); $card->setAssignedUsers($cardAssignedUsers);
@@ -175,16 +175,17 @@ class CardService {
public function find(int $cardId) { public function find(int $cardId) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ);
$card = $this->cardMapper->find($cardId); $card = $this->cardMapper->find($cardId);
$assignedUsers = $this->assignedUsersMapper->findAll($card->getId()); $this->enrichCards([$card]);
// Attachments are only enriched on individual card fetching
$attachments = $this->attachmentService->findAll($cardId, true); $attachments = $this->attachmentService->findAll($cardId, true);
if ($this->request->getParam('apiVersion') === '1.0') { if ($this->request->getParam('apiVersion') === '1.0') {
$attachments = array_filter($attachments, function ($attachment) { $attachments = array_filter($attachments, function ($attachment) {
return $attachment->getType() === 'deck_file'; return $attachment->getType() === 'deck_file';
}); });
} }
$card->setAssignedUsers($assignedUsers);
$card->setAttachments($attachments); $card->setAttachments($attachments);
$this->enrichCards([$card]);
return $card; return $card;
} }

View File

@@ -82,7 +82,6 @@ class SearchService {
}, $boards); }, $boards);
$matchedCards = $this->cardMapper->search($boardIds, $this->filterStringParser->parse($term), $limit, $cursor); $matchedCards = $this->cardMapper->search($boardIds, $this->filterStringParser->parse($term), $limit, $cursor);
$self = $this;
return $this->cardService->enrichCards($matchedCards); return $this->cardService->enrichCards($matchedCards);
} }