Skip to content

Commit

Permalink
TASK: Remove ContentGraphInterface::countNodes as the method is not b…
Browse files Browse the repository at this point in the history
…ound to a workspace but cross content stream

Also since its internal and only used for the tests it a good to be hidden in the low level `ContentRepositoryReadModel` next to other low level methods
  • Loading branch information
mhsdesign committed Oct 8, 2024
1 parent a39c50e commit f11e713
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ public function findUnusedAndRemovedContentStreamIds(): iterable
return array_map(ContentStreamId::fromString(...), $contentStreamIds);
}

public function countNodes(): int
{
$countNodesStatement = <<<SQL
SELECT
COUNT(*)
FROM
{$this->tableNames->node()}
SQL;
try {
return (int)$this->dbal->fetchOne($countNodesStatement);
} catch (Exception $e) {
throw new \RuntimeException(sprintf('Failed to count rows in database: %s', $e->getMessage()), 1701444590, $e);
}
}

/**
* @param array<string, mixed> $row
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,6 @@ public function getDimensionSpacePointsOccupiedByChildNodeName(NodeName $nodeNam
return new DimensionSpacePointSet($dimensionSpacePoints);
}

public function countNodes(): int
{
$queryBuilder = $this->createQueryBuilder()
->select('COUNT(*)')
->from($this->nodeQueryBuilder->tableNames->node());
try {
$result = $queryBuilder->executeQuery();
return (int)$result->fetchOne();
} catch (DBALException $e) {
throw new \RuntimeException(sprintf('Failed to count rows in database: %s', $e->getMessage()), 1701444590, $e);
}
}

public function findUsedNodeTypeNames(): NodeTypeNames
{
return NodeTypeNames::fromArray(array_map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ public function findUnusedAndRemovedContentStreamIds(): iterable
// TODO: Implement getUnusedAndRemovedContentStreamIds() method.
return [];
}

public function countNodes(): int
{
// TODO: Implement countNodes method.
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,6 @@ public function getDimensionSpacePointsOccupiedByChildNodeName(
return new DimensionSpacePointSet($occupiedDimensionSpacePoints);
}

/**
* @throws \Doctrine\DBAL\Driver\Exception
* @throws \Doctrine\DBAL\Exception
*/
public function countNodes(): int
{
$query = 'SELECT COUNT(*) FROM ' . $this->tableNamePrefix . '_node';

return $this->dbal->executeQuery($query)->fetchOne();
}

public function findUsedNodeTypeNames(): NodeTypeNames
{
return NodeTypeNames::createEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ public function findContentStreams(): ContentStreams;
* @internal This is currently only used by the {@see ContentStreamPruner} and might be removed in the future!
*/
public function findUnusedAndRemovedContentStreamIds(): iterable;

/**
* Provides the total number of projected nodes regardless of workspace or content stream.
*
* @internal only for consumption in testcases
*/
public function countNodes(): int;
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ public function getDimensionSpacePointsOccupiedByChildNodeName(
DimensionSpacePointSet $dimensionSpacePointsToCheck
): DimensionSpacePointSet;

/**
* Provides the total number of projected nodes regardless of workspace or content stream.
*
* @internal only for consumption in testcases
*/
public function countNodes(): int;

/** @internal The content stream id where the workspace name points to for this instance */
public function getContentStreamId(): ContentStreamId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Neos\ContentRepository\Core\ContentRepositoryReadModel;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryDependencies;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceInterface;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite;
Expand Down Expand Up @@ -154,7 +156,20 @@ public function workspaceHasStatus(string $rawWorkspaceName, string $status): vo
*/
public function iExpectTheGraphProjectionToConsistOfExactlyNodes(int $expectedNumberOfNodes): void
{
$actualNumberOfNodes = $this->currentContentRepository->getContentGraph($this->currentWorkspaceName)->countNodes();
// HACK to access
$contentRepositoryReadModelAccess = new class implements ContentRepositoryServiceFactoryInterface {
public ContentRepositoryReadModel|null $instance;
public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface
{
$this->instance = $serviceFactoryDependencies->projectionsAndCatchUpHooks->readModelProjection->getState();
return new class implements ContentRepositoryServiceInterface
{
};
}
};
$this->getContentRepositoryService($contentRepositoryReadModelAccess);

$actualNumberOfNodes = $contentRepositoryReadModelAccess->instance->countNodes();
Assert::assertSame($expectedNumberOfNodes, $actualNumberOfNodes, 'Content graph consists of ' . $actualNumberOfNodes . ' nodes, expected were ' . $expectedNumberOfNodes . '.');
}

Expand Down

0 comments on commit f11e713

Please sign in to comment.