Skip to content

Commit

Permalink
TASK: Cleanup enumeration code
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Nov 22, 2023
1 parent a59129f commit b07abbc
Showing 1 changed file with 19 additions and 33 deletions.
52 changes: 19 additions & 33 deletions Classes/NodeEnumeration/NodeEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@
use Flowpack\DecoupledContentStore\PrepareContentRelease\Infrastructure\RedisContentReleaseService;
use Flowpack\DecoupledContentStore\Utility\GeneratorUtility;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\NodeType\NodeTypeConstraintFactory;
use Neos\ContentRepository\Domain\NodeType\NodeTypeName;
use Neos\ContentRepository\Domain\Utility\NodePaths;
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Model\Site;

class NodeEnumerator
{
/**
* @Flow\Inject
* @var NodeTypeConstraintFactory
*/
protected $nodeTypeConstraintFactory;

/**
* @Flow\Inject
Expand Down Expand Up @@ -79,9 +71,16 @@ private function enumerateAll(?Site $site, ContentReleaseLogger $contentReleaseL
{
$combinator = new NodeContextCombinator();

$nodeTypeWhitelist = $this->nodeTypeConstraintFactory->parseFilterString($this->nodeTypeWhitelist);
// Build filter from white listed nodetypes
$nodeTypeWhitelist = explode(',', $this->nodeTypeWhitelist ?: 'Neos.Neos:Document');
$nodeTypeFilter = implode(',', array_map(static function ($nodeType) {
if ($nodeType[0] === '!') {
return '[!instanceof ' . substr($nodeType, 1) . ']';
}
return '[instanceof ' . $nodeType . ']';
}, $nodeTypeWhitelist));

$queueSite = function (Site $site) use ($combinator, $nodeTypeWhitelist, $contentReleaseLogger, $workspaceName) {
$queueSite = static function (Site $site) use ($combinator, $nodeTypeFilter, $contentReleaseLogger, $workspaceName) {
$contentReleaseLogger->debug('Publishing site', [
'name' => $site->getName(),
'domain' => $site->getFirstActiveDomain()
Expand All @@ -94,24 +93,15 @@ private function enumerateAll(?Site $site, ContentReleaseLogger $contentReleaseL
'dimensionValues' => $dimensionValues
]);

// Build filter from white listed nodetypes
$nodeTypeWhitelist = explode(',', $this->nodeTypeWhitelist ?: 'Neos.Neos:Document');
$nodeTypeFilter = implode(',', array_map(static function ($nodeType) {
if ($nodeType[0] === '!') {
return '[!instanceof ' . substr($nodeType, 1) . ']';
}
return '[instanceof ' . $nodeType . ']';
}, $nodeTypeWhitelist));

$documentQuery = new FlowQuery([$siteNode]);
/** @var NodeInterface[] $documents */
$documents = $documentQuery->find($nodeTypeFilter)->add($siteNode)->get();
$nodeQuery = new FlowQuery([$siteNode]);
/** @var NodeInterface[] $matchingNodes */
$matchingNodes = $nodeQuery->find($nodeTypeFilter)->add($siteNode)->get();

foreach ($documents as $documentNode) {
$contextPath = $documentNode->getContextPath();
foreach ($matchingNodes as $nodeToEnumerate) {
$contextPath = $nodeToEnumerate->getContextPath();

// Verify that the node is not orphaned
$parentNode = $documentNode->getParent();
$parentNode = $nodeToEnumerate->getParent();
while ($parentNode !== $siteNode) {
if ($parentNode === null) {
$contentReleaseLogger->debug('Skipping node from publishing, because it is orphaned', [
Expand All @@ -123,28 +113,24 @@ private function enumerateAll(?Site $site, ContentReleaseLogger $contentReleaseL
$parentNode = $parentNode->getParent();
}

if (!$documentNode->getParent()) {
$contentReleaseLogger->debug('Skipping node from publishing, because it is orphaned', [
'node' => $contextPath,
]);
} else if ($documentNode->isHidden()) {
if ($nodeToEnumerate->isHidden()) {
$contentReleaseLogger->debug('Skipping node from publishing, because it is hidden', [
'node' => $contextPath,
]);
} else {
$contentReleaseLogger->debug('Registering node for publishing', [
'node' => $contextPath
]);
yield EnumeratedNode::fromNode($documentNode);
yield EnumeratedNode::fromNode($nodeToEnumerate);
}
}
}
$contentReleaseLogger->debug(sprintf('Finished enumerating site %s in %dms', $site->getName(), (microtime(true) - $startTime) * 1000));
};

if ($site === null) {
foreach ($combinator->sites() as $site) {
yield from $queueSite($site);
foreach ($combinator->sites() as $siteInList) {
yield from $queueSite($siteInList);
}
} else {
yield from $queueSite($site);
Expand Down

0 comments on commit b07abbc

Please sign in to comment.