Skip to content

Commit

Permalink
BUGFIX: Fix content cache for discard, revert neos#5083 for now
Browse files Browse the repository at this point in the history
The change was taken too lightly and the whole content cache flushing depends on the assumption that after publishing or discard, everything will be rendered.
With this knowledge and the added test we should be able to refactor it correctly in the feature without introducing a regression again.
  • Loading branch information
mhsdesign committed Jun 23, 2024
1 parent 77f1812 commit 368f2c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Neos.Neos/Classes/Fusion/Cache/NodeCacheEntryIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Neos\Neos\Fusion\Cache;

use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\Flow\Annotations as Flow;
use Neos\Cache\CacheAwareInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
Expand All @@ -22,17 +23,18 @@
* The cache entry identifier data transfer object for nodes
*
* @Flow\Proxy(false)
* @internal
*/
final class NodeCacheEntryIdentifier implements CacheAwareInterface
final readonly class NodeCacheEntryIdentifier implements CacheAwareInterface
{
private function __construct(
private readonly string $value
private string $value
) {
}

public static function fromNode(Node $node): self
public static function fromNode(Node $node, ContentStreamId $contentStreamId): self
{
return new self('Node_' . $node->workspaceName->value
return new self('Node_' . $contentStreamId->value
. '_' . $node->dimensionSpacePoint->hash
. '_' . $node->aggregateId->value);
}
Expand Down
12 changes: 11 additions & 1 deletion Neos.Neos/Classes/Fusion/Helper/CachingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Eel\ProtectedContextAwareInterface;
use Neos\Flow\Annotations as Flow;
Expand All @@ -38,6 +39,11 @@ class CachingHelper implements ProtectedContextAwareInterface
*/
protected $contentRepositoryRegistry;

/**
* @var array<string, ContentStreamId>
*/
private array $workspaceNameToContentStreamIdMapping = [];

/**
* Generate a `@cache` entry tag for a single node, array of nodes or a FlowQuery result
* A cache entry with this tag will be flushed whenever one of the
Expand Down Expand Up @@ -70,7 +76,11 @@ public function nodeTag(iterable|Node $nodes): array
*/
public function entryIdentifierForNode(Node $node): NodeCacheEntryIdentifier
{
return NodeCacheEntryIdentifier::fromNode($node);
// Todo adjust content caching to work with workspaces as entry identifier than the content stream id
$currentContentStreamId = $this->workspaceNameToContentStreamIdMapping[$node->contentRepositoryId->value . '@' . $node->workspaceName->value]
??= $this->contentRepositoryRegistry->get($node->contentRepositoryId)->getContentGraph($node->workspaceName)->getContentStreamId();

return NodeCacheEntryIdentifier::fromNode($node, $currentContentStreamId);
}

/**
Expand Down

0 comments on commit 368f2c9

Please sign in to comment.