diff --git a/Neos.Neos/Classes/View/FusionView.php b/Neos.Neos/Classes/View/FusionView.php index 5f8d50363fe..3e998b6e1c8 100644 --- a/Neos.Neos/Classes/View/FusionView.php +++ b/Neos.Neos/Classes/View/FusionView.php @@ -72,13 +72,7 @@ public function render(): ResponseInterface|StreamInterface { $currentNode = $this->getCurrentNode(); - $subgraph = $this->contentRepositoryRegistry->subgraphForNode($currentNode); - $currentSiteNode = $subgraph->findClosestNode($currentNode->aggregateId, FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_SITE)); - - if (!$currentSiteNode) { - throw new \RuntimeException('No site node found!', 1697053346); - } - + $currentSiteNode = $this->getCurrentSiteNode(); $fusionRuntime = $this->getFusionRuntime($currentSiteNode); $this->setFallbackRuleFromDimension($currentNode->dimensionSpacePoint); @@ -165,6 +159,12 @@ public function getFusionPath() protected function getClosestDocumentNode(Node $node): ?Node { + $nodeTypeManager = $this->contentRepositoryRegistry->get($node->contentRepositoryId)->getNodeTypeManager(); + + // Skip expensive subgraph lookup if the node is already a document node + if ($nodeTypeManager->getNodeType($node->nodeTypeName)?->isOfType(NodeTypeNameFactory::NAME_DOCUMENT)) { + return $node; + } return $this->contentRepositoryRegistry->subgraphForNode($node) ->findClosestNode($node->aggregateId, FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_DOCUMENT)); } @@ -175,11 +175,20 @@ protected function getClosestDocumentNode(Node $node): ?Node */ protected function getCurrentSiteNode(): Node { - $currentNode = $this->variables['site'] ?? null; - if (!$currentNode instanceof Node) { - throw new Exception('FusionView needs a variable \'site\' set with a Node object.', 1538996432); + $currentSiteNode = $this->variables['site'] ?? null; + if (!$currentSiteNode instanceof Node) { + $currentNode = $this->getCurrentNode(); + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($currentNode); + $currentSiteNode = $subgraph->findClosestNode( + $currentNode->aggregateId, + FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_SITE) + ); + $this->assign('site', $currentSiteNode); } - return $currentNode; + if (!$currentSiteNode) { + throw new \RuntimeException('No site node found!', 1697053346); + } + return $currentSiteNode; } /**