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 all 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
9 changes: 4 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ jobs:
# We enable the race condition tracker
presets:
'default':
projections:
'Neos.ContentRepository:ContentGraph':
catchUpHooks:
'Neos.ContentRepository.BehavioralTests:RaceConditionTracker':
factoryObjectName: Neos\ContentRepository\BehavioralTests\ProjectionRaceConditionTester\RaceTrackerCatchUpHookFactory
contentGraphProjection:
catchUpHooks:
'Neos.ContentRepository.BehavioralTests:RaceConditionTracker':
factoryObjectName: Neos\ContentRepository\BehavioralTests\ProjectionRaceConditionTester\RaceTrackerCatchUpHookFactory
ContentRepository:
BehavioralTests:
raceConditionTracker:
Expand Down
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\Projection\ContentGraph\ContentGraphReadModelInterface;
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 ContentGraphReadModelAdapter implements ContentGraphReadModelInterface
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
{
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 @@ -17,7 +17,7 @@
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\NodeRelationAnchorPoint;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\DimensionSpacePointsRepository;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ProjectionContentGraph;
use Neos\ContentRepository\Core\ContentRepositoryReadModel;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphReadModelInterface;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
Expand Down 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\ContentGraph\ContentGraphProjectionInterface;
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 ContentGraphProjectionInterface
{
use ContentStream;
use NodeMove;
Expand All @@ -98,7 +97,7 @@ public function __construct(
private readonly ProjectionContentGraph $projectionContentGraph,
private readonly ContentGraphTableNames $tableNames,
private readonly DimensionSpacePointsRepository $dimensionSpacePointsRepository,
private readonly ContentRepositoryReadModel $contentRepositoryReadModel
private readonly ContentGraphReadModelInterface $contentGraphReadModel
) {
$this->checkpointStorage = new DbalCheckpointStorage(
$this->dbal,
Expand Down Expand Up @@ -177,9 +176,9 @@ public function getCheckpointStorage(): DbalCheckpointStorage
return $this->checkpointStorage;
}

public function getState(): ContentRepositoryReadModel
public function getState(): ContentGraphReadModelInterface
{
return $this->contentRepositoryReadModel;
return $this->contentGraphReadModel;
}

public function canHandle(EventInterface $event): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@
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;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphProjectionFactoryInterface;

/**
* Use this class as ProjectionFactory in your configuration to construct a content graph
*
* @implements ProjectionFactoryInterface<DoctrineDbalContentGraphProjection>
*
* @api
*/
final class DoctrineDbalContentGraphProjectionFactory implements ProjectionFactoryInterface
final class DoctrineDbalContentGraphProjectionFactory implements ContentGraphProjectionFactoryInterface
{
public function __construct(
private readonly Connection $dbal,
Expand All @@ -42,7 +39,7 @@ public function build(
$dimensionSpacePointsRepository
);

$contentRepositoryReadModelAdapter = new ContentRepositoryReadModelAdapter(
$contentGraphReadModel = new ContentGraphReadModelAdapter(
$this->dbal,
$nodeFactory,
$projectionFactoryDependencies->contentRepositoryId,
Expand All @@ -58,7 +55,7 @@ public function build(
),
$tableNames,
$dimensionSpacePointsRepository,
new ContentRepositoryReadModel($contentRepositoryReadModelAdapter)
$contentGraphReadModel
);
}
}
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 @@ -7,8 +7,7 @@
use Doctrine\DBAL\Connection;
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\Projection\ContentGraph\ContentGraphReadModelInterface;
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 ContentHyperGraphReadModelAdapter implements ContentGraphReadModelInterface
{
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 @@ -26,7 +26,7 @@
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\Feature\NodeVariation;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\Feature\SubtreeTagging;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\SchemaBuilder\HypergraphSchemaBuilder;
use Neos\ContentRepository\Core\ContentRepositoryReadModel;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphReadModelInterface;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\ContentStreamForking\Event\ContentStreamWasForked;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
Expand All @@ -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\ContentGraph\ContentGraphProjectionInterface;
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 ContentGraphProjectionInterface
{
use ContentStreamForking;
use NodeCreation;
Expand All @@ -73,7 +72,7 @@ final class HypergraphProjection implements ProjectionInterface
public function __construct(
private readonly Connection $dbal,
private readonly string $tableNamePrefix,
private readonly ContentRepositoryReadModel $contentRepositoryReadModel
private readonly ContentGraphReadModelInterface $contentGraphReadModel
) {
$this->projectionHypergraph = new ProjectionHypergraph($this->dbal, $this->tableNamePrefix);
$this->checkpointStorage = new DbalCheckpointStorage(
Expand Down Expand Up @@ -219,9 +218,9 @@ public function getCheckpointStorage(): DbalCheckpointStorage
return $this->checkpointStorage;
}

public function getState(): ContentRepositoryReadModel
public function getState(): ContentGraphReadModelInterface
{
return $this->contentRepositoryReadModel;
return $this->contentGraphReadModel;
}

protected function getProjectionHypergraph(): ProjectionHypergraph
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,16 +7,14 @@
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\Projection\ContentGraph\ContentGraphProjectionFactoryInterface;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;

/**
* @implements ProjectionFactoryInterface<HypergraphProjection>
* @api
*/
final class HypergraphProjectionFactory implements ProjectionFactoryInterface
final class HypergraphProjectionFactory implements ContentGraphProjectionFactoryInterface
{
public function __construct(
private readonly Connection $dbal,
Expand Down Expand Up @@ -45,7 +43,7 @@ public function build(
return new HypergraphProjection(
$this->dbal,
$tableNamePrefix,
new ContentRepositoryReadModel(new ContentHyperRepositoryReadModelAdapter($this->dbal, $nodeFactory, $projectionFactoryDependencies->contentRepositoryId, $projectionFactoryDependencies->nodeTypeManager, $tableNamePrefix))
new ContentHyperGraphReadModelAdapter($this->dbal, $nodeFactory, $projectionFactoryDependencies->contentRepositoryId, $projectionFactoryDependencies->nodeTypeManager, $tableNamePrefix)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Neos:
#ContentRepositoryRegistry:
# presets:
# 'default':
# projections:
# 'Neos.ContentRepository:ContentGraph':
# contentGraphProjection:
# catchUpHooks:
# 'Neos.ContentRepository.BehavioralTests:RaceConditionTracker':
# factoryObjectName: Neos\ContentRepository\BehavioralTests\ProjectionRaceConditionTester\RaceTrackerCatchUpHookFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Neos:
ContentRepositoryRegistry:
presets:
'default':
projections:
'Neos.ContentRepository:ContentGraph':
factoryObjectName: Neos\ContentGraph\PostgreSQLAdapter\HypergraphProjectionFactory
contentGraphProjection:
factoryObjectName: Neos\ContentGraph\PostgreSQLAdapter\HypergraphProjectionFactory

Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ Neos:
# We enable the race condition tracker. For details on how this works, see RaceTrackerCatchUpHook.php
presets:
'default':
projections:
'Neos.ContentRepository:ContentGraph':
catchUpHooks:
'Neos.ContentRepository.BehavioralTests:RaceConditionTracker':
factoryObjectName: Neos\ContentRepository\BehavioralTests\ProjectionRaceConditionTester\RaceTrackerCatchUpHookFactory
contentGraphProjection:
catchUpHooks:
'Neos.ContentRepository.BehavioralTests:RaceConditionTracker':
factoryObjectName: Neos\ContentRepository\BehavioralTests\ProjectionRaceConditionTester\RaceTrackerCatchUpHookFactory
ContentRepository:
BehavioralTests:
raceConditionTracker:
Expand Down
Loading
Loading