perf(cards): fetch all cards at once

Instead of one by one

Signed-off-by: Carl Schwan <carl.schwan@nextclound.com>
This commit is contained in:
Carl Schwan
2025-08-13 14:50:54 +02:00
parent 0ed8b21b3c
commit a3fa72341d
5 changed files with 58 additions and 21 deletions

View File

@@ -75,19 +75,22 @@ class StackService {
$this->stackServiceValidator = $stackServiceValidator;
}
private function enrichStackWithCards($stack, $since = -1) {
$cards = $this->cardMapper->findAll($stack->getId(), null, null, $since);
/** @param Stack[] $stacks */
private function enrichStacksWithCards(array $stacks, $since = -1): void {
$cardsByStackId = $this->cardMapper->findAllForStacks(array_map(fn (Stack $stack) => $stack->getId(), $stacks), null, null, $since);
if (\count($cards) === 0) {
return;
}
foreach ($cardsByStackId as $stackId => $cards) {
if (!$cards) {
continue;
}
$stack->setCards($this->cardService->enrichCards($cards));
}
private function enrichStacksWithCards($stacks, $since = -1) {
foreach ($stacks as $stack) {
$this->enrichStackWithCards($stack, $since);
foreach ($stacks as $stack) {
if ($stack->getId() === $stackId) {
$stack->setCards($this->cardService->enrichCards($cards));
break;
}
}
}
}
@@ -124,9 +127,9 @@ class StackService {
}
/**
* @param $boardId
* @param mixed $boardId
*
* @return array
* @return Stack[]
* @throws \OCA\Deck\NoPermissionException
* @throws BadRequestException
*/
@@ -247,7 +250,7 @@ class StackService {
);
$this->changeHelper->boardChanged($stack->getBoardId());
$this->eventDispatcher->dispatchTyped(new BoardUpdatedEvent($stack->getBoardId()));
$this->enrichStackWithCards($stack);
$this->enrichStacksWithCards([$stack]);
return $stack;
}