Skip to content

Commit

Permalink
Revert "TASK: Reintroduce content graph / cr read model cache"
Browse files Browse the repository at this point in the history
In commit 2a781d2 the cache invalidation was partly repaired
But as we removed the content graph cache layer currently in 9.0 #5246

A reintroduction will be discussed as part of another change.

Related #5039
  • Loading branch information
mhsdesign committed Oct 15, 2024
1 parent b41f5b5 commit 2a8b490
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Timestamps;
use Neos\ContentRepository\Core\Projection\ProjectionInterface;
use Neos\ContentRepository\Core\Projection\ProjectionStatus;
use Neos\ContentRepository\Core\Projection\WithMarkStaleInterface;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
Expand All @@ -80,7 +79,7 @@
* @implements ProjectionInterface<ContentRepositoryReadModel>
* @internal but the graph projection is api
*/
final class DoctrineDbalContentGraphProjection implements ProjectionInterface, WithMarkStaleInterface
final class DoctrineDbalContentGraphProjection implements ProjectionInterface
{
use ContentStream;
use NodeMove;
Expand Down Expand Up @@ -170,12 +169,6 @@ public function reset(): void

$this->checkpointStorage->acquireLock();
$this->checkpointStorage->updateAndReleaseLock(SequenceNumber::none());
$this->getState()->forgetInstances();
}

public function markStale(): void
{
$this->getState()->forgetInstances();
}

public function getCheckpointStorage(): DbalCheckpointStorage
Expand Down
57 changes: 6 additions & 51 deletions Neos.ContentRepository.Core/Classes/ContentRepositoryReadModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\Projection\ProjectionStateInterface;
use Neos\ContentRepository\Core\Projection\WithMarkStaleInterface;
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStream;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
Expand All @@ -35,48 +34,14 @@
*/
final class ContentRepositoryReadModel implements ProjectionStateInterface
{
/**
* @var array<string, ContentGraphInterface> Runtime cache for {@see ContentGraphInterface} instances, indexed by their workspace name
*/
private array $contentGraphInstancesByWorkspaceName = [];

/**
* @var array<string, Workspace> Runtime cache for {@see Workspace} instances, indexed by their name
*/
private array $workspaceInstancesByName = [];

/**
* @var array<string, ContentStream> Runtime cache for {@see ContentStream} instances, indexed by their name
*/
private array $contentStreamInstancesById = [];

public function __construct(
private readonly ContentRepositoryReadModelAdapterInterface $adapter
) {
}

/**
* To release all held instances, in case a workspace/content stream relation needs to be reset
*
* @internal Must be invoked by the projection {@see WithMarkStaleInterface::markStale()} to ensure a flush after write operations
*/
public function forgetInstances(): void
{
$this->contentGraphInstancesByWorkspaceName = [];
$this->workspaceInstancesByName = [];
$this->contentStreamInstancesById = [];
}

public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace
{
if (!array_key_exists($workspaceName->value, $this->workspaceInstancesByName)) {
$workspace = $this->adapter->findWorkspaceByName($workspaceName);
if ($workspace === null) {
return null;
}
$this->workspaceInstancesByName[$workspaceName->value] = $workspace;
}
return $this->workspaceInstancesByName[$workspaceName->value];
return $this->adapter->findWorkspaceByName($workspaceName);
}

public function findWorkspaces(): Workspaces
Expand All @@ -86,14 +51,7 @@ public function findWorkspaces(): Workspaces

public function findContentStreamById(ContentStreamId $contentStreamId): ?ContentStream
{
if (!array_key_exists($contentStreamId->value, $this->contentStreamInstancesById)) {
$contentStream = $this->adapter->findContentStreamById($contentStreamId);
if ($contentStream === null) {
return null;
}
$this->contentStreamInstancesById[$contentStreamId->value] = $contentStream;
}
return $this->contentStreamInstancesById[$contentStreamId->value];
return $this->adapter->findContentStreamById($contentStreamId);
}

public function findContentStreams(): ContentStreams
Expand All @@ -119,14 +77,11 @@ public function findUnusedAndRemovedContentStreamIds(): iterable
*/
public function getContentGraphByWorkspaceName(WorkspaceName $workspaceName): ContentGraphInterface
{
if (!array_key_exists($workspaceName->value, $this->contentGraphInstancesByWorkspaceName)) {
$workspace = $this->findWorkspaceByName($workspaceName);
if ($workspace === null) {
throw WorkspaceDoesNotExist::butWasSupposedTo($workspaceName);
}
$this->contentGraphInstancesByWorkspaceName[$workspaceName->value] = $this->adapter->buildContentGraph($workspace->workspaceName, $workspace->currentContentStreamId);
$workspace = $this->findWorkspaceByName($workspaceName);
if ($workspace === null) {
throw WorkspaceDoesNotExist::butWasSupposedTo($workspaceName);
}
return $this->contentGraphInstancesByWorkspaceName[$workspaceName->value];
return $this->adapter->buildContentGraph($workspace->workspaceName, $workspace->currentContentStreamId);
}

/**
Expand Down

0 comments on commit 2a8b490

Please sign in to comment.