Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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 @@ -17,7 +17,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Query\QueryBuilder;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\ContentStreamDbId;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\ContentStreamLayers;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentGraph;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
Expand Down Expand Up @@ -51,27 +51,27 @@ public function getContentGraph(WorkspaceName $workspaceName): ContentGraph
$currentContentStreamIdStatement = <<<SQL
SELECT
ws.currentContentStreamId,
cs.dbId AS contentStreamDbId
l.contentStreamLayer
FROM
{$this->tableNames->workspace()} ws
JOIN {$this->tableNames->contentStream()} cs ON cs.id = ws.currentContentStreamId
JOIN {$this->tableNames->contentStreamLayer()} l ON l.contentStreamId = ws.currentContentStreamId
WHERE
ws.name = :workspaceName
LIMIT 1
SQL;
try {
$row = $this->dbal->fetchAssociative($currentContentStreamIdStatement, [
$rows = $this->dbal->fetchAllAssociative($currentContentStreamIdStatement, [
'workspaceName' => $workspaceName->value,
]);
} catch (Exception $e) {
throw new \RuntimeException(sprintf('Failed to load current content stream id from database: %s', $e->getMessage()), 1716903166, $e);
}
if ($row === false) {
if ($rows === []) {
throw WorkspaceDoesNotExist::butWasSupposedTo($workspaceName);
}
$currentContentStreamId = ContentStreamId::fromString($row['currentContentStreamId']);
$contentStreamDbId = ContentStreamDbId::fromInt((int)$row['contentStreamDbId']);
return new ContentGraph($this->dbal, $this->nodeFactory, $this->contentRepositoryId, $this->nodeTypeManager, $this->tableNames, $workspaceName, $currentContentStreamId, $contentStreamDbId);
$firstRow = reset($rows);
$currentContentStreamId = ContentStreamId::fromString($firstRow['currentContentStreamId']);
$contentStreamLayers = ContentStreamLayers::fromArray(array_column($rows, 'contentStreamLayer'));
return new ContentGraph($this->dbal, $this->nodeFactory, $this->contentRepositoryId, $this->nodeTypeManager, $this->tableNames, $workspaceName, $currentContentStreamId, $contentStreamLayers);
}

public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public function contentStream(): string
{
return $this->tableNamePrefix . '_contentstream';
}

public function contentStreamLayer(): string
{
return $this->tableNamePrefix . '_contentstreamlayer';
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Neos\ContentGraph\DoctrineDbalAdapter;

use Doctrine\DBAL\Connection;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentStreamDbIdFinder;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentStreamLayerFinder;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\DimensionSpacePointsRepository;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ProjectionContentGraph;
Expand All @@ -32,7 +32,7 @@ public function build(
);

$dimensionSpacePointsRepository = new DimensionSpacePointsRepository($this->dbal, $tableNames);
$contentStreamDbIdRepository = new ContentStreamDbIdFinder($this->dbal, $tableNames);
$contentStreamLayerFinder = new ContentStreamLayerFinder($this->dbal, $tableNames);

$nodeFactory = new NodeFactory(
$projectionFactoryDependencies->contentRepositoryId,
Expand All @@ -56,7 +56,7 @@ public function build(
),
$tableNames,
$dimensionSpacePointsRepository,
$contentStreamDbIdRepository,
$contentStreamLayerFinder,
$contentGraphReadModel
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function buildSchema(Connection $connection): Schema
$this->createDimensionSpacePointsTable($connection->getDatabasePlatform()),
$this->createWorkspaceTable($connection->getDatabasePlatform()),
$this->createContentStreamTable($connection->getDatabasePlatform()),
$this->createContentStreamLayerTable($connection->getDatabasePlatform()),
]);
}

Expand Down Expand Up @@ -61,21 +62,25 @@ private function createNodeTable(AbstractPlatform $platform): Table
private function createHierarchyRelationTable(AbstractPlatform $platform): Table
{
$table = self::createTable($this->tableNames->hierarchyRelation(), [
(new Column('id', Type::getType(Types::INTEGER)))->setAutoincrement(true)->setNotnull(true),
(new Column('contentstreamlayer', self::type(Types::INTEGER)))->setNotnull(true),
(new Column('position', self::type(Types::INTEGER)))->setNotnull(true),
(new Column('contentstreamdbid', self::type(Types::INTEGER)))->setNotnull(true),
DbalSchemaFactory::columnForDimensionSpacePointHash('dimensionspacepointhash', $platform)->setNotnull(true),
DbalSchemaFactory::columnForNodeAnchorPoint('parentnodeanchor', $platform),
DbalSchemaFactory::columnForNodeAnchorPoint('childnodeanchor', $platform),
// todo nullable?
DbalSchemaFactory::columnForNodeAnchorPoint('parentnodeanchor', $platform)->setNotnull(false),
DbalSchemaFactory::columnForNodeAnchorPoint('childnodeanchor', $platform)->setNotnull(false),
(new Column('subtreetags', self::type(Types::JSON))),
]);

return $table
->addIndex(['id'])
->addUniqueIndex(['id', 'contentstreamlayer'])
->addIndex(['childnodeanchor'])
->addIndex(['contentstreamdbid'])
->addIndex(['contentstreamlayer'])
->addIndex(['parentnodeanchor'])
->addIndex(['childnodeanchor', 'contentstreamdbid', 'dimensionspacepointhash', 'position'])
->addIndex(['parentnodeanchor', 'contentstreamdbid', 'dimensionspacepointhash', 'position'])
->addIndex(['contentstreamdbid', 'dimensionspacepointhash']);
->addIndex(['childnodeanchor', 'contentstreamlayer', 'dimensionspacepointhash', 'position'])
->addIndex(['parentnodeanchor', 'contentstreamlayer', 'dimensionspacepointhash', 'position'])
->addIndex(['contentstreamlayer', 'dimensionspacepointhash']);
}

private function createDimensionSpacePointsTable(AbstractPlatform $platform): Table
Expand Down Expand Up @@ -120,7 +125,6 @@ private function createWorkspaceTable(AbstractPlatform $platform): Table
private function createContentStreamTable(AbstractPlatform $platform): Table
{
$contentStreamTable = self::createTable($this->tableNames->contentStream(), [
(new Column('dbId', Type::getType(Types::INTEGER)))->setAutoincrement(true)->setNotnull(true),
DbalSchemaFactory::columnForContentStreamId('id', $platform)->setNotnull(true),
(new Column('version', Type::getType(Types::INTEGER)))->setNotnull(true),
DbalSchemaFactory::columnForContentStreamId('sourceContentStreamId', $platform)->setNotnull(false),
Expand All @@ -130,8 +134,19 @@ private function createContentStreamTable(AbstractPlatform $platform): Table
]);

return $contentStreamTable
->addUniqueIndex(['id'])
->setPrimaryKey(['dbId']);
->setPrimaryKey(['id']);
}

private function createContentStreamLayerTable(AbstractPlatform $platform): Table
{
$contentStreamLayerTable = self::createTable($this->tableNames->contentStreamLayer(), [
DbalSchemaFactory::columnForContentStreamId('contentStreamId', $platform)->setNotnull(true),
(new Column('contentStreamLayer', Type::getType(Types::INTEGER)))->setAutoincrement(true)->setNotnull(true),
]);

return $contentStreamLayerTable
->addIndex(['contentStreamLayer'])
->setPrimaryKey(['contentStreamId', 'contentStreamLayer']);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection;

/**
* @internal
*/
final readonly class ContentStreamLayer
{
private function __construct(
public int $value
) {
if ($value < 0) {
throw new \InvalidArgumentException('A ContentStreamLayer cannot be negative, got %d', $value);
}
}

public function equals(ContentStreamLayer $id): bool
{
return $this->value === $id->value;
}

public static function fromInt(int $value): self
{
return new self($value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection;

/**
* @internal
*/
final readonly class ContentStreamLayers
{
/**
* @param array<int,ContentStreamLayer> $items
*/
private function __construct(
// todo remove all usages
// public int $value,
public array $items
) {
}

public static function from(ContentStreamLayer ...$items): self
{
if ($items === []) {
throw new \InvalidArgumentException('Db ids must not be empty', 1775819046);
}
$indexed = [];
foreach ($items as $id) {
$indexed[$id->value] = $id;
}
return new self(
items: $indexed,
);
}

/** @param array<int|string,int> $array */
public static function fromArray(array $array): self
{
return self::from(
...array_map(ContentStreamLayer::fromInt(...), $array),
);
}

public function getWriteLayer(): ContentStreamLayer
{
return $this->items[max(array_keys($this->items))];
}

public function equals(ContentStreamLayer $id): bool
{
return count($this->items) === 1 && array_key_exists($id->value, $this->items);
}

public function contain(ContentStreamLayer $id): bool
{
return array_key_exists($id->value, $this->items);
}

/**
* @return list<int>
*/
public function toIntArray(): array
{
return array_keys($this->items);
}

public function toDebugString(): string
{
return sprintf('DbIds[%s]', join(',', $this->toIntArray()));
}
}
Loading
Loading