Skip to content

Commit f32243b

Browse files
committed
TASK: Refactor WorkspaceIndexer to optimize node traversal.
1 parent 1392927 commit f32243b

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Classes/Indexer/WorkspaceIndexer.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
*/
1515

1616
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
17-
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
18-
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter;
19-
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
20-
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
17+
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter;
2118
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
2219
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
2320
use Neos\ContentRepository\Search\Indexer\NodeIndexingManager;
2421
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
2522
use Neos\Flow\Annotations as Flow;
23+
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
24+
use Neos\Neos\Domain\SubtreeTagging\NeosVisibilityConstraints;
2625

2726
/**
2827
* Workspace Indexer for Content Repository Nodes.
@@ -73,27 +72,27 @@ public function index(ContentRepositoryId $contentRepositoryId, WorkspaceName $w
7372
public function indexWithDimensions(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, DimensionSpacePoint $dimensionSpacePoint, ?int $limit = null, ?callable $callback = null): int
7473
{
7574
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
75+
$contentGraph = $contentRepository->getContentGraph($workspaceName);
76+
77+
$rootNodeAggregate = $contentGraph->findRootNodeAggregateByType(NodeTypeNameFactory::forSites());
78+
$subgraph = $contentGraph->getSubgraph($dimensionSpacePoint, NeosVisibilityConstraints::excludeRemoved());
7679

77-
$rootNodeAggregate = $contentRepository->getContentGraph($workspaceName)->findRootNodeAggregateByType(NodeTypeName::fromString('Neos.Neos:Sites'));
78-
$subgraph = $contentRepository->getContentGraph($workspaceName)->getSubgraph($dimensionSpacePoint, VisibilityConstraints::withoutRestrictions());
7980
$rootNode = $subgraph->findNodeById($rootNodeAggregate->nodeAggregateId);
8081
$indexedNodes = 0;
8182

82-
$traverseNodes = function (Node $currentNode, &$indexedNodes) use ($subgraph, $limit, &$traverseNodes) {
83+
$this->nodeIndexingManager->indexNode($rootNode);
84+
$indexedNodes++;
85+
86+
foreach ($subgraph->findDescendantNodes($rootNode->aggregateId, FindDescendantNodesFilter::create()) as $descendantNode) {
8387
if ($limit !== null && $indexedNodes > $limit) {
84-
return;
88+
break;
8589
}
8690

87-
$this->nodeIndexingManager->indexNode($currentNode);
91+
$this->nodeIndexingManager->indexNode($descendantNode);
8892
$indexedNodes++;
8993

90-
array_map(function (Node $childNode) use ($traverseNodes, &$indexedNodes) {
91-
$traverseNodes($childNode, $indexedNodes);
92-
}, iterator_to_array($subgraph->findChildNodes($currentNode->aggregateId, FindChildNodesFilter::create())->getIterator()));
9394
};
9495

95-
$traverseNodes($rootNode, $indexedNodes);
96-
9796
$this->nodeIndexingManager->flushQueues();
9897

9998
if ($callback !== null) {

0 commit comments

Comments
 (0)