perf: Combine fetching acls for boards
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -52,6 +52,17 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
return $this->findEntities($qb);
|
return $this->findEntities($qb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findIn(array $boardIds, ?int $limit = null, ?int $offset = null): array {
|
||||||
|
$qb = $this->db->getQueryBuilder();
|
||||||
|
$qb->select('id', 'board_id', 'type', 'participant', 'permission_edit', 'permission_share', 'permission_manage')
|
||||||
|
->from('deck_board_acl')
|
||||||
|
->where($qb->expr()->in('board_id', $qb->createNamedParameter($boardIds, IQueryBuilder::PARAM_INT_ARRAY)))
|
||||||
|
->setMaxResults($limit)
|
||||||
|
->setFirstResult($offset);
|
||||||
|
|
||||||
|
return $this->findEntities($qb);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param numeric $userId
|
* @param numeric $userId
|
||||||
* @param numeric $id
|
* @param numeric $id
|
||||||
|
|||||||
@@ -160,6 +160,20 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
|
|||||||
$groupBoards = $this->findAllByGroups($userId, $groups, null, null, $since, $includeArchived, $before, $term);
|
$groupBoards = $this->findAllByGroups($userId, $groups, null, null, $since, $includeArchived, $before, $term);
|
||||||
$circleBoards = $this->findAllByCircles($userId, null, null, $since, $includeArchived, $before, $term);
|
$circleBoards = $this->findAllByCircles($userId, null, null, $since, $includeArchived, $before, $term);
|
||||||
$allBoards = array_unique(array_merge($userBoards, $groupBoards, $circleBoards));
|
$allBoards = array_unique(array_merge($userBoards, $groupBoards, $circleBoards));
|
||||||
|
|
||||||
|
// Could be moved outside
|
||||||
|
$acls = $this->aclMapper->findIn(array_map(function ($board) {
|
||||||
|
return $board->getId();
|
||||||
|
}, $allBoards));
|
||||||
|
|
||||||
|
/* @var Board $entry */
|
||||||
|
foreach ($allBoards as $entry) {
|
||||||
|
$boardAcls = array_filter($acls, function ($acl) use ($entry) {
|
||||||
|
return $acl->getBoardId() === $entry->getId();
|
||||||
|
});
|
||||||
|
$entry->setAcl($boardAcls);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($allBoards as $board) {
|
foreach ($allBoards as $board) {
|
||||||
$this->boardCache[$board->getId()] = $board;
|
$this->boardCache[$board->getId()] = $board;
|
||||||
}
|
}
|
||||||
@@ -259,11 +273,7 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
|
|||||||
$entry->setShared(1);
|
$entry->setShared(1);
|
||||||
}
|
}
|
||||||
$entries = array_merge($entries, $sharedEntries);
|
$entries = array_merge($entries, $sharedEntries);
|
||||||
/* @var Board $entry */
|
|
||||||
foreach ($entries as $entry) {
|
|
||||||
$acl = $this->aclMapper->findAll($entry->id);
|
|
||||||
$entry->setAcl($acl);
|
|
||||||
}
|
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,11 +346,6 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
|
|||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$entry->setShared(2);
|
$entry->setShared(2);
|
||||||
}
|
}
|
||||||
/* @var Board $entry */
|
|
||||||
foreach ($entries as $entry) {
|
|
||||||
$acl = $this->aclMapper->findAll($entry->id);
|
|
||||||
$entry->setAcl($acl);
|
|
||||||
}
|
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,11 +402,6 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
|
|||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$entry->setShared(2);
|
$entry->setShared(2);
|
||||||
}
|
}
|
||||||
/* @var Board $entry */
|
|
||||||
foreach ($entries as $entry) {
|
|
||||||
$acl = $this->aclMapper->findAll($entry->id);
|
|
||||||
$entry->setAcl($acl);
|
|
||||||
}
|
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user