Skip to content

Commit

Permalink
ContentNodeRepository: also fetch root and parent of contentNode
Browse files Browse the repository at this point in the history
With the ResponsiveLayout, we now have mostly ContentNodes which are nested by 2 levels:
ColumnLayout -> DefaultLayout -> "Content Nodes with content"
This may lead to n+1 db queries that we experienced in the EndpointQueryCountTest.
  • Loading branch information
BacLuc committed Dec 10, 2023
1 parent e2d2c14 commit 8917fcc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions api/src/Repository/ContentNodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ public function __construct(EntityManagerInterface $em, string $entityClass = Co
public function filterByUser(QueryBuilder $queryBuilder, User $user): void {
$this->filterByContentNode($queryBuilder, $user, $queryBuilder->getRootAliases()[0]);
}

public function createQueryBuilder($alias, $indexBy = null): QueryBuilder {
$qb = parent::createQueryBuilder($alias, $indexBy);
$qb->select("{$alias}", 'fetchRoot', 'fetchParent', 'fetchParentOfParent');
$qb->leftJoin("{$alias}.root", 'fetchRoot');
$qb->leftJoin("{$alias}.parent", 'fetchParent');
$qb->leftJoin('fetchParent.parent', 'fetchParentOfParent');

return $qb;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/camp_collaborations/item: 15
/categories: 11
/categories/item: 9
/content_nodes: 9
/content_nodes: 8
/content_node/column_layouts: 6
/content_node/column_layouts/item: 10
/content_node/material_nodes: 6
Expand Down

0 comments on commit 8917fcc

Please sign in to comment.