Skip to content

Commit

Permalink
WIP: Add WorkspaceName to Subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Feb 20, 2024
1 parent 44ae083 commit b1faa80
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregates;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Exception\RootNodeAggregateDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\DetachedWorkspaceName;

/**
* The Doctrine DBAL adapter content graph
Expand Down Expand Up @@ -76,16 +78,20 @@ public function __construct(
}

final public function getSubgraph(
ContentStreamId $contentStreamId,
ContentStreamId|Workspace $contentStreamReference,
DimensionSpacePoint $dimensionSpacePoint,
VisibilityConstraints $visibilityConstraints
): ContentSubgraphInterface {
$contentStreamId = $contentStreamReference instanceof Workspace ? $contentStreamReference->currentContentStreamId : $contentStreamReference;
$index = $contentStreamId->value . '-' . $dimensionSpacePoint->hash . '-' . $visibilityConstraints->getHash();
if (!isset($this->subgraphs[$index])) {
$this->subgraphs[$index] = new ContentSubgraphWithRuntimeCaches(
new ContentSubgraph(
$this->contentRepositoryId,
$contentStreamId,
$contentStreamReference instanceof Workspace
? $contentStreamReference->workspaceName
: null,
$dimensionSpacePoint,
$visibilityConstraints,
$this->client,
Expand All @@ -96,6 +102,7 @@ final public function getSubgraph(
);
}

// todo how to add current workspace name to this cached subgraph?
return $this->subgraphs[$index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Node\PropertyName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
* The content subgraph application repository
Expand Down Expand Up @@ -106,6 +107,7 @@ final class ContentSubgraph implements ContentSubgraphInterface
public function __construct(
private readonly ContentRepositoryId $contentRepositoryId,
private readonly ContentStreamId $contentStreamId,
private readonly ?WorkspaceName $workspaceName,
private readonly DimensionSpacePoint $dimensionSpacePoint,
private readonly VisibilityConstraints $visibilityConstraints,
private readonly DbalClientInterface $client,
Expand Down Expand Up @@ -328,7 +330,7 @@ public function findSubtree(NodeAggregateId $entryNodeAggregateId, FindSubtreeFi
foreach (array_reverse($result) as $nodeData) {
$nodeAggregateId = $nodeData['nodeaggregateid'];
$parentNodeAggregateId = $nodeData['parentNodeAggregateId'];
$node = $this->nodeFactory->mapNodeRowToNode($nodeData, $this->dimensionSpacePoint, $this->visibilityConstraints);
$node = $this->nodeFactory->mapNodeRowToNode($nodeData, $this->dimensionSpacePoint, $this->visibilityConstraints, $this->workspaceName);
$subtree = new Subtree((int)$nodeData['level'], $node, array_key_exists($nodeAggregateId, $subtreesByParentNodeId) ? array_reverse($subtreesByParentNodeId[$nodeAggregateId]) : []);
if ($subtree->level === 0) {
return $subtree;
Expand Down Expand Up @@ -358,7 +360,8 @@ public function findAncestorNodes(NodeAggregateId $entryNodeAggregateId, FindAnc
return $this->nodeFactory->mapNodeRowsToNodes(
$nodeRows,
$this->dimensionSpacePoint,
$this->visibilityConstraints
$this->visibilityConstraints,
$this->workspaceName
);
}

Expand Down Expand Up @@ -418,7 +421,8 @@ public function findClosestNode(NodeAggregateId $entryNodeAggregateId, FindClose
return $this->nodeFactory->mapNodeRowsToNodes(
$nodeRows,
$this->dimensionSpacePoint,
$this->visibilityConstraints
$this->visibilityConstraints,
$this->workspaceName
)->first();
}

Expand All @@ -433,7 +437,7 @@ public function findDescendantNodes(NodeAggregateId $entryNodeAggregateId, FindD
}
$queryBuilderCte->addOrderBy('level')->addOrderBy('position');
$nodeRows = $this->fetchCteResults($queryBuilderInitial, $queryBuilderRecursive, $queryBuilderCte, 'tree');
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->dimensionSpacePoint, $this->visibilityConstraints);
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->dimensionSpacePoint, $this->visibilityConstraints, $this->workspaceName);
}

public function countDescendantNodes(NodeAggregateId $entryNodeAggregateId, CountDescendantNodesFilter $filter): int
Expand Down Expand Up @@ -883,7 +887,8 @@ private function fetchNode(QueryBuilder $queryBuilder): ?Node
return $this->nodeFactory->mapNodeRowToNode(
$nodeRow,
$this->dimensionSpacePoint,
$this->visibilityConstraints
$this->visibilityConstraints,
$this->workspaceName
);
}

Expand All @@ -894,7 +899,7 @@ private function fetchNodes(QueryBuilder $queryBuilder): Nodes
} catch (DbalDriverException | DbalException $e) {
throw new \RuntimeException(sprintf('Failed to fetch nodes: %s', $e->getMessage()), 1678292896, $e);
}
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->dimensionSpacePoint, $this->visibilityConstraints);
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->dimensionSpacePoint, $this->visibilityConstraints, $this->workspaceName);
}

private function fetchCount(QueryBuilder $queryBuilder): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\Infrastructure\Property\PropertyConverter;
use Neos\ContentRepository\Core\SharedModel\Workspace\DetachedWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
* Implementation detail of ContentGraph and ContentSubgraph
Expand All @@ -63,7 +64,8 @@ public function __construct(
public function mapNodeRowToNode(
array $nodeRow,
DimensionSpacePoint $dimensionSpacePoint,
VisibilityConstraints $visibilityConstraints
VisibilityConstraints $visibilityConstraints,
?WorkspaceName $workspaceName,
): Node {
$nodeType = $this->nodeTypeManager->hasNodeType($nodeRow['nodetypename'])
? $this->nodeTypeManager->getNodeType($nodeRow['nodetypename'])
Expand All @@ -72,8 +74,7 @@ public function mapNodeRowToNode(
return Node::create(
NodeIdentity::create(
$this->contentRepositoryId,
// todo use "real" WorkspaceName if available.
DetachedWorkspaceName::fromContentStreamId(
$workspaceName ?? DetachedWorkspaceName::fromContentStreamId(
ContentStreamId::fromString($nodeRow['contentstreamid'])
),
$dimensionSpacePoint,
Expand Down Expand Up @@ -104,10 +105,10 @@ public function mapNodeRowToNode(
/**
* @param array<int, array<string, mixed>> $nodeRows
*/
public function mapNodeRowsToNodes(array $nodeRows, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints): Nodes
public function mapNodeRowsToNodes(array $nodeRows, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints, ?WorkspaceName $workspaceName): Nodes
{
return Nodes::fromArray(
array_map(fn (array $nodeRow) => $this->mapNodeRowToNode($nodeRow, $dimensionSpacePoint, $visibilityConstraints), $nodeRows)
array_map(fn (array $nodeRow) => $this->mapNodeRowToNode($nodeRow, $dimensionSpacePoint, $visibilityConstraints, $workspaceName), $nodeRows)
);
}

Expand All @@ -132,7 +133,8 @@ public function mapReferenceRowsToReferences(
$node = $this->mapNodeRowToNode(
$nodeRow,
$dimensionSpacePoint,
$visibilityConstraints
$visibilityConstraints,
null // todo
);
$result[] = new Reference(
$node,
Expand Down Expand Up @@ -180,7 +182,8 @@ public function mapNodeRowsToNodeAggregate(
$nodesByOccupiedDimensionSpacePoints[$occupiedDimensionSpacePoint->hash] = $this->mapNodeRowToNode(
$nodeRow,
$occupiedDimensionSpacePoint->toDimensionSpacePoint(),
$visibilityConstraints
$visibilityConstraints,
null // todo
);
$occupiedDimensionSpacePoints[] = $occupiedDimensionSpacePoint;
$rawNodeAggregateId = $rawNodeAggregateId ?: $nodeRow['nodeaggregateid'];
Expand Down Expand Up @@ -262,7 +265,8 @@ public function mapNodeRowsToNodeAggregates(
[$rawNodeAggregateId][$occupiedDimensionSpacePoint->hash] = $this->mapNodeRowToNode(
$nodeRow,
$occupiedDimensionSpacePoint->toDimensionSpacePoint(),
$visibilityConstraints
$visibilityConstraints,
null // todo
);
$occupiedDimensionSpacePointsByNodeAggregate[$rawNodeAggregateId][]
= $occupiedDimensionSpacePoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindRootNodeAggregatesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregates;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Exception\RootNodeAggregateDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
Expand Down Expand Up @@ -69,10 +70,11 @@ public function __construct(
}

public function getSubgraph(
ContentStreamId $contentStreamId,
ContentStreamId|Workspace $contentStreamReference,
DimensionSpacePoint $dimensionSpacePoint,
VisibilityConstraints $visibilityConstraints
): ContentSubgraphInterface {
$contentStreamId = $contentStreamReference instanceof Workspace ? $contentStreamReference->currentContentStreamId : $contentStreamReference;
$index = $contentStreamId->value . '-' . $dimensionSpacePoint->hash . '-' . $visibilityConstraints->getHash();
if (!isset($this->subhypergraphs[$index])) {
$this->subhypergraphs[$index] = new ContentSubhypergraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\Projection\ProjectionStateInterface;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Exception\RootNodeAggregateDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
Expand All @@ -40,7 +41,7 @@ interface ContentGraphInterface extends ProjectionStateInterface
* @api main API method of ContentGraph
*/
public function getSubgraph(
ContentStreamId $contentStreamId,
ContentStreamId|Workspace $contentStreamReference,
DimensionSpacePoint $dimensionSpacePoint,
VisibilityConstraints $visibilityConstraints
): ContentSubgraphInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
*/
final class NodeAggregate
{
// todo add workspace name?
public function __construct(
public readonly ContentStreamId $contentStreamId,
public readonly NodeAggregateId $nodeAggregateId,
Expand Down

0 comments on commit b1faa80

Please sign in to comment.