Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!! TASK: Introduce first level content repository projection #5272

Merged
merged 16 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Doctrine\DBAL\Exception;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentGraph;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentRepository\Core\ContentRepositoryReadModelAdapterInterface;
use Neos\ContentRepository\Core\ContentRepositoryReadModel;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStream;
Expand All @@ -32,10 +32,9 @@
use Neos\EventStore\Model\Event\Version;

/**
* @internal only used inside the
* @see ContentRepositoryReadModel
* @internal
*/
final readonly class ContentRepositoryReadModelAdapter implements ContentRepositoryReadModelAdapterInterface
final readonly class ContentRepositoryReadModelAdapter implements ContentRepositoryReadModel
{
public function __construct(
private Connection $dbal,
Expand Down Expand Up @@ -131,6 +130,21 @@ public function findContentStreams(): ContentStreams
return ContentStreams::fromArray(array_map(self::contentStreamFromDatabaseRow(...), $rows));
}

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 @@ -65,8 +65,8 @@
use Neos\ContentRepository\Core\Projection\CheckpointStorageStatusType;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTags;
use Neos\ContentRepository\Core\Projection\ContentGraph\Timestamps;
use Neos\ContentRepository\Core\Projection\ProjectionInterface;
use Neos\ContentRepository\Core\Projection\ProjectionStatus;
use Neos\ContentRepository\Core\Projection\ContentRepositoryReadModelProjection;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
Expand All @@ -76,10 +76,9 @@
use Neos\EventStore\Model\EventEnvelope;

/**
* @implements ProjectionInterface<ContentRepositoryReadModel>
* @internal but the graph projection is api
*/
final class DoctrineDbalContentGraphProjection implements ProjectionInterface
final class DoctrineDbalContentGraphProjection implements ContentRepositoryReadModelProjection
{
use ContentStream;
use NodeMove;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\DimensionSpacePointsRepository;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ProjectionContentGraph;
use Neos\ContentRepository\Core\ContentRepositoryReadModel;
use Neos\ContentRepository\Core\Factory\ProjectionFactoryDependencies;
use Neos\ContentRepository\Core\Projection\ProjectionFactoryInterface;

Expand Down Expand Up @@ -42,7 +41,7 @@ public function build(
$dimensionSpacePointsRepository
);

$contentRepositoryReadModelAdapter = new ContentRepositoryReadModelAdapter(
$contentRepositoryReadModel = new ContentRepositoryReadModelAdapter(
$this->dbal,
$nodeFactory,
$projectionFactoryDependencies->contentRepositoryId,
Expand All @@ -58,7 +57,7 @@ public function build(
),
$tableNames,
$dimensionSpacePointsRepository,
new ContentRepositoryReadModel($contentRepositoryReadModelAdapter)
$contentRepositoryReadModel
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,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 @@ -8,7 +8,6 @@
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Repository\ContentHypergraph;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Repository\NodeFactory;
use Neos\ContentRepository\Core\ContentRepositoryReadModel;
use Neos\ContentRepository\Core\ContentRepositoryReadModelAdapterInterface;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
Expand All @@ -20,10 +19,9 @@
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces;

/**
* @internal only used within
* @see ContentRepositoryReadModel
* @internal
*/
final readonly class ContentHyperRepositoryReadModelAdapter implements ContentRepositoryReadModelAdapterInterface
final readonly class ContentHyperRepositoryReadModelAdapter implements ContentRepositoryReadModel
{
public function __construct(
private Connection $dbal,
Expand Down Expand Up @@ -62,4 +60,10 @@ public function findContentStreams(): ContentStreams
// TODO: Implement getContentStreams() method.
return ContentStreams::createEmpty();
}

public function countNodes(): int
{
// TODO: Implement countNodes method.
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@
use Neos\ContentRepository\Core\Infrastructure\DbalCheckpointStorage;
use Neos\ContentRepository\Core\Infrastructure\DbalSchemaDiff;
use Neos\ContentRepository\Core\Projection\CheckpointStorageStatusType;
use Neos\ContentRepository\Core\Projection\ProjectionInterface;
use Neos\ContentRepository\Core\Projection\ProjectionStatus;
use Neos\ContentRepository\Core\Projection\ContentRepositoryReadModelProjection;
use Neos\EventStore\Model\Event\SequenceNumber;
use Neos\EventStore\Model\EventEnvelope;

/**
* The alternate reality-aware hypergraph projector for the PostgreSQL backend via Doctrine DBAL
*
* @implements ProjectionInterface<ContentRepositoryReadModel>
* @internal the parent Content Graph is public
*/
final class HypergraphProjection implements ProjectionInterface
final class HypergraphProjection implements ContentRepositoryReadModelProjection
{
use ContentStreamForking;
use NodeCreation;
Expand Down
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 @@ -7,7 +7,6 @@
use Doctrine\DBAL\Connection;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\HypergraphProjection;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Repository\NodeFactory;
use Neos\ContentRepository\Core\ContentRepositoryReadModel;
use Neos\ContentRepository\Core\Factory\ProjectionFactoryDependencies;
use Neos\ContentRepository\Core\Projection\ProjectionFactoryInterface;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
Expand Down Expand Up @@ -45,7 +44,7 @@ public function build(
return new HypergraphProjection(
$this->dbal,
$tableNamePrefix,
new ContentRepositoryReadModel(new ContentHyperRepositoryReadModelAdapter($this->dbal, $nodeFactory, $projectionFactoryDependencies->contentRepositoryId, $projectionFactoryDependencies->nodeTypeManager, $tableNamePrefix))
new ContentHyperRepositoryReadModelAdapter($this->dbal, $nodeFactory, $projectionFactoryDependencies->contentRepositoryId, $projectionFactoryDependencies->nodeTypeManager, $tableNamePrefix)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ final class CommandHandlingDependencies
*/
private array $overriddenContentGraphInstances = [];

public function __construct(private readonly ContentRepository $contentRepository)
{
public function __construct(
private readonly ContentRepository $contentRepository,
private readonly ContentRepositoryReadModel $adapter
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
) {
}

public function handle(CommandInterface $command): CommandResult
Expand All @@ -49,7 +51,7 @@ public function handle(CommandInterface $command): CommandResult

public function getContentStreamVersion(ContentStreamId $contentStreamId): Version
{
$contentStream = $this->contentRepository->findContentStreamById($contentStreamId);
$contentStream = $this->adapter->findContentStreamById($contentStreamId);
if ($contentStream === null) {
throw new \InvalidArgumentException(sprintf('Failed to find content stream with id "%s"', $contentStreamId->value), 1716902051);
}
Expand All @@ -58,12 +60,12 @@ public function getContentStreamVersion(ContentStreamId $contentStreamId): Versi

public function contentStreamExists(ContentStreamId $contentStreamId): bool
{
return $this->contentRepository->findContentStreamById($contentStreamId) !== null;
return $this->adapter->findContentStreamById($contentStreamId) !== null;
}

public function getContentStreamStatus(ContentStreamId $contentStreamId): ContentStreamStatus
{
$contentStream = $this->contentRepository->findContentStreamById($contentStreamId);
$contentStream = $this->adapter->findContentStreamById($contentStreamId);
if ($contentStream === null) {
throw new \InvalidArgumentException(sprintf('Failed to find content stream with id "%s"', $contentStreamId->value), 1716902219);
}
Expand All @@ -72,7 +74,7 @@ public function getContentStreamStatus(ContentStreamId $contentStreamId): Conten

public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace
{
return $this->contentRepository->findWorkspaceByName($workspaceName);
return $this->adapter->findWorkspaceByName($workspaceName);
}

/**
Expand All @@ -83,8 +85,11 @@ public function getContentGraph(WorkspaceName $workspaceName): ContentGraphInter
if (isset($this->overriddenContentGraphInstances[$workspaceName->value])) {
return $this->overriddenContentGraphInstances[$workspaceName->value];
}

return $this->contentRepository->getContentGraph($workspaceName);
$workspace = $this->adapter->findWorkspaceByName($workspaceName);
if ($workspace === null) {
throw WorkspaceDoesNotExist::butWasSupposedTo($workspaceName);
}
bwaidelich marked this conversation as resolved.
Show resolved Hide resolved
return $this->adapter->buildContentGraph($workspace->workspaceName, $workspace->currentContentStreamId);
}

/**
Expand All @@ -102,7 +107,7 @@ public function overrideContentStreamId(WorkspaceName $workspaceName, ContentStr
throw new \RuntimeException('Contentstream override for this workspace already in effect, nesting not allowed.', 1715170938);
}

$contentGraph = $this->contentRepository->projectionState(ContentRepositoryReadModel::class)->getContentGraphByWorkspaceNameAndContentStreamId($workspaceName, $contentStreamId);
$contentGraph = $this->adapter->buildContentGraph($workspaceName, $contentStreamId);
$this->overriddenContentGraphInstances[$workspaceName->value] = $contentGraph;

try {
Expand Down
Loading
Loading