Skip to content

Commit

Permalink
BUGFIX: Improve performance on buildAncestorNodesQueries
Browse files Browse the repository at this point in the history
  • Loading branch information
dlubitz committed Oct 2, 2024
1 parent e02a778 commit 142551a
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ private function buildAncestorNodesQueries(NodeAggregateId $entryNodeAggregateId
// The parent node anchor points to the first parent node of the given node aggregate. This is also used for
// the recursive part, to determine its ancestors.
$queryBuilderInitial = $this->createQueryBuilder()
->select('ph.subtreetags, ph.parentnodeanchor')
->select('ph.subtreetags, ph.parentnodeanchor, ph.childnodeanchor')
->from($this->nodeQueryBuilder->tableNames->hierarchyRelation(), 'ph')
->innerJoin('ph', $this->nodeQueryBuilder->tableNames->node(), 'c', 'c.relationanchorpoint = ph.childnodeanchor')
->andWhere('ph.contentstreamid = :contentStreamId')
Expand All @@ -575,7 +575,7 @@ private function buildAncestorNodesQueries(NodeAggregateId $entryNodeAggregateId
// 2) Fetch the parent hierarchy recursive, starting with the anchor point of the resulting parent as child anchor
// point for the next iteration.
$queryBuilderRecursive = $this->createQueryBuilder()
->select('h.subtreetags, h.parentnodeanchor')
->select('h.subtreetags, h.parentnodeanchor, h.childnodeanchor')
->from('ancestry', 'cn')
->innerJoin('cn', $this->nodeQueryBuilder->tableNames->hierarchyRelation(), 'h', 'h.childnodeanchor = cn.parentnodeanchor')
->where('h.contentstreamid = :contentStreamId')
Expand All @@ -584,7 +584,7 @@ private function buildAncestorNodesQueries(NodeAggregateId $entryNodeAggregateId

$queryBuilderCte = $this->nodeQueryBuilder->buildBasicNodesCteQuery($entryNodeAggregateId, $this->contentStreamId, $this->dimensionSpacePoint, 'ancestry', 'a');
// 3) Finally we join the node table to all collected parent node anchor
$queryBuilderCte->innerJoin('a', $this->nodeQueryBuilder->tableNames->node(), 'pn', 'pn.relationanchorpoint = a.parentnodeanchor');
$queryBuilderCte->innerJoin('a', $this->nodeQueryBuilder->tableNames->node(), 'pn', 'pn.relationanchorpoint = a.childnodeanchor AND pn.nodeaggregateid <> :entryNodeAggregateId');

if ($filter->nodeTypes !== null) {
$this->nodeQueryBuilder->addNodeTypeCriteria($queryBuilderCte, ExpandedNodeTypeCriteria::create($filter->nodeTypes, $this->nodeTypeManager), 'pn');
Expand Down

0 comments on commit 142551a

Please sign in to comment.