Skip to content

Commit

Permalink
Merge pull request neos#5254 from dlubitz/90/task/add-test-for-conten…
Browse files Browse the repository at this point in the history
…tcacheflush-on-rebase

BUGFIX: Flush content cache on rebase workspace
  • Loading branch information
dlubitz authored Sep 19, 2024
2 parents a0b6d26 + 4396f07 commit 78936ce
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasUntagged;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPartiallyDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Event\WorkspaceWasRebased;
use Neos\ContentRepository\Core\Infrastructure\DbalCheckpointStorage;
use Neos\ContentRepository\Core\Infrastructure\DbalSchemaDiff;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
Expand Down Expand Up @@ -166,7 +167,8 @@ public function canHandle(EventInterface $event): bool
SubtreeWasTagged::class,
SubtreeWasUntagged::class,
WorkspaceWasDiscarded::class,
WorkspaceWasPartiallyDiscarded::class
WorkspaceWasPartiallyDiscarded::class,
WorkspaceWasRebased::class
]);
}

Expand All @@ -191,11 +193,12 @@ public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
RootNodeAggregateWithNodeWasCreated::class => $this->whenRootNodeAggregateWithNodeWasCreated($event, $eventEnvelope),
SubtreeWasTagged::class => $this->whenSubtreeWasTagged($event),
SubtreeWasUntagged::class => $this->whenSubtreeWasUntagged($event),
// the following two events are not actually handled, but we need to include them in {@see canHandle()} in order
// the following three events are not actually handled, but we need to include them in {@see canHandle()} in order
// to trigger the catchup hooks for those (i.e. {@see GraphProjectorCatchUpHookForCacheFlushing}). This can
// be removed with https://github.com/neos/neos-development-collection/issues/4992
WorkspaceWasDiscarded::class => null,
WorkspaceWasPartiallyDiscarded::class => null,
WorkspaceWasDiscarded::class,
WorkspaceWasPartiallyDiscarded::class,
WorkspaceWasRebased::class => null,
default => throw new \InvalidArgumentException(sprintf('Unsupported event %s', get_debug_type($event))),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasUntagged;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPartiallyDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Event\WorkspaceWasRebased;
use Neos\ContentRepository\Core\Projection\CatchUpHookInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
Expand Down Expand Up @@ -130,7 +131,8 @@ public function canHandle(EventInterface $event): bool
SubtreeWasTagged::class,
SubtreeWasUntagged::class,
WorkspaceWasDiscarded::class,
WorkspaceWasPartiallyDiscarded::class
WorkspaceWasPartiallyDiscarded::class,
WorkspaceWasRebased::class
]);
}

Expand Down Expand Up @@ -186,6 +188,7 @@ public function onAfterEvent(EventInterface $eventInstance, EventEnvelope $event
if (
$eventInstance instanceof WorkspaceWasDiscarded
|| $eventInstance instanceof WorkspaceWasPartiallyDiscarded
|| $eventInstance instanceof WorkspaceWasRebased
) {
$this->scheduleCacheFlushJobForWorkspaceName($this->contentRepository, $eventInstance->workspaceName);
} elseif (
Expand Down Expand Up @@ -260,7 +263,10 @@ public function onBeforeBatchCompleted(): void
public function onAfterCatchUp(): void
{
foreach ($this->flushNodeAggregateRequestsOnAfterCatchUp as $request) {
$this->contentCacheFlusher->flushNodeAggregate($request, CacheFlushingStrategy::IMMEDIATE);
// We do not need to flush single node aggregates if we flush the whole workspace anyway.
if (!isset($this->flushWorkspaceRequestsOnAfterCatchUp[$request->workspaceName->value])) {
$this->contentCacheFlusher->flushNodeAggregate($request, CacheFlushingStrategy::IMMEDIATE);
}
}
$this->flushNodeAggregateRequestsOnAfterCatchUp = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ Feature: Tests for the ContentCacheFlusher and cache flushing when applied in us
include: resource://Neos.Neos/Private/Fusion/Root.fusion
prototype(Neos.Neos:Test.TextNode) < prototype(Neos.Neos:ContentComponent) {
renderer = ${"[" + q(node).property("text") + "]"}
cacheVerifier = ${null}
renderer = ${props.cacheVerifier + "[" + q(node).property("text") + "]"}
}
"""

Expand Down Expand Up @@ -245,3 +246,53 @@ Feature: Tests for the ContentCacheFlusher and cache flushing when applied in us
"""
<div class="neos-contentcollection">[Text Node at the start of the document][Text Node in the middle of the document has changed][Text Node at the end of the document]</div>
"""

Scenario: ContentCache gets flushed when a workspace gets rebased
Given I have Fusion content cache enabled
And I am in workspace "user-editor" and dimension space point {}
And the Fusion context node is "test-document-with-contents"
And I execute the following Fusion code:
"""fusion
test = Neos.Neos:ContentCollection {
prototype(Neos.Neos:Test.TextNode) {
cacheVerifier = "firstRender"
}
nodePath = "main"
}
"""
Then I expect the following Fusion rendering result:
"""
<div class="neos-contentcollection">firstRender[Text Node at the start of the document]firstRender[Text Node at the end of the document]</div>
"""

When I am in workspace "live" and dimension space point {}
And the command CreateNodeAggregateWithNode is executed with payload:
| Key | Value |
| nodeAggregateId | "text-node-middle" |
| nodeTypeName | "Neos.Neos:Test.TextNode" |
| parentNodeAggregateId | "test-document-with-contents--main" |
| initialPropertyValues | {"text": "Text Node in the middle of the document"} |
| succeedingSiblingNodeAggregateId | "text-node-end" |
| nodeName | "text-node-middle" |

When I am in workspace "user-editor" and dimension space point {}
And the command RebaseWorkspace is executed with payload:
| Key | Value |
| workspaceName | "user-editor" |
| rebasedContentStreamId | "user-editor-cs-identifier-rebased" |
Then I expect node aggregate identifier "text-node-middle" to lead to node user-editor-cs-identifier-rebased;text-node-middle;{}

When I execute the following Fusion code:
"""fusion
test = Neos.Neos:ContentCollection {
prototype(Neos.Neos:Test.TextNode) {
cacheVerifier = "secondRender"
}
nodePath = "main"
}
"""
Then I expect the following Fusion rendering result:
"""
<div class="neos-contentcollection">secondRender[Text Node at the start of the document]secondRender[Text Node in the middle of the document]secondRender[Text Node at the end of the document]</div>
"""

0 comments on commit 78936ce

Please sign in to comment.