Skip to content

Commit a85b10a

Browse files
committed
BUGFIX: Skip site node query in FusionView if node is already available
We use the existing method to get the site node and fall back to the query if necessary.
1 parent 0570af6 commit a85b10a

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

Neos.Neos/Classes/View/FusionView.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
namespace Neos\Neos\View;
1616

17-
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
1817
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindClosestNodeFilter;
1918
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
2019
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
@@ -56,8 +55,6 @@ class FusionView extends AbstractView
5655
#[Flow\Inject]
5756
protected RenderingModeService $renderingModeService;
5857

59-
protected NodeTypeManager $nodeTypeManager;
60-
6158
/**
6259
* Via {@see assign} request using the "request" key,
6360
* will be available also as Fusion global in the runtime.
@@ -75,19 +72,11 @@ public function render(): ResponseInterface|StreamInterface
7572
{
7673
$currentNode = $this->getCurrentNode();
7774

78-
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($currentNode);
79-
$currentSiteNode = $subgraph->findClosestNode($currentNode->aggregateId, FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_SITE));
80-
81-
if (!$currentSiteNode) {
82-
throw new \RuntimeException('No site node found!', 1697053346);
83-
}
84-
75+
$currentSiteNode = $this->getCurrentSiteNode();
8576
$fusionRuntime = $this->getFusionRuntime($currentSiteNode);
8677

8778
$this->setFallbackRuleFromDimension($currentNode->dimensionSpacePoint);
8879

89-
$this->nodeTypeManager = $this->contentRepositoryRegistry->get($subgraph->getContentRepositoryId())->getNodeTypeManager();
90-
9180
return $fusionRuntime->renderEntryPathWithContext($this->fusionPath, [
9281
'node' => $currentNode,
9382
'documentNode' => $this->getClosestDocumentNode($currentNode) ?: $currentNode,
@@ -170,8 +159,10 @@ public function getFusionPath()
170159

171160
protected function getClosestDocumentNode(Node $node): ?Node
172161
{
162+
$nodeTypeManager = $this->contentRepositoryRegistry->get($node->contentRepositoryId)->getNodeTypeManager();
163+
173164
// Skip expensive subgraph lookup if the node is already a document node
174-
if ($this->nodeTypeManager->getNodeType($node->nodeTypeName)?->isOfType(NodeTypeNameFactory::NAME_DOCUMENT)) {
165+
if ($nodeTypeManager->getNodeType($node->nodeTypeName)?->isOfType(NodeTypeNameFactory::NAME_DOCUMENT)) {
175166
return $node;
176167
}
177168
return $this->contentRepositoryRegistry->subgraphForNode($node)
@@ -184,11 +175,20 @@ protected function getClosestDocumentNode(Node $node): ?Node
184175
*/
185176
protected function getCurrentSiteNode(): Node
186177
{
187-
$currentNode = $this->variables['site'] ?? null;
188-
if (!$currentNode instanceof Node) {
189-
throw new Exception('FusionView needs a variable \'site\' set with a Node object.', 1538996432);
178+
$currentSiteNode = $this->variables['site'] ?? null;
179+
if (!$currentSiteNode instanceof Node) {
180+
$currentNode = $this->getCurrentNode();
181+
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($currentNode);
182+
$currentSiteNode = $subgraph->findClosestNode(
183+
$currentNode->aggregateId,
184+
FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_SITE)
185+
);
186+
$this->assign('site', $currentSiteNode);
190187
}
191-
return $currentNode;
188+
if (!$currentSiteNode) {
189+
throw new \RuntimeException('No site node found!', 1697053346);
190+
}
191+
return $currentSiteNode;
192192
}
193193

194194
/**

0 commit comments

Comments
 (0)