Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions Neos.Neos/Classes/View/FusionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally we should not need the node type manager here because if the view is used in the controller where we only route to documents we can trust the input and not be paranoid.

(asking things the node type manager loads and initialises the configuration which is also work which is ideally not part of the rendering?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes as with all those variables, the controller should supply them and the view should complain if not. Though I think in this case the Neos FusionView accepted any kind of node so far.

I would like to fix this for 9.x if we agree on the breakinesslevel.

return $node;
}
return $this->contentRepositoryRegistry->subgraphForNode($node)
->findClosestNode($node->aggregateId, FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_DOCUMENT));
}
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So previously this case failed and now we try to fetch the site?
Wouldn't this disguise potential bugs? And is that related to the performance optimization?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now the 8.3 behaviour again.
8.3 looked for the site in the context if it wasn't defined by the controller.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why it affects performance is, that the method is called at least twice.

$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;
}

/**
Expand Down