From 889b61e30b3ff04c2ecd2e335d6e7e72c4a0a85e Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Thu, 19 Sep 2024 11:22:13 +0200 Subject: [PATCH 1/5] TASK: Add test case for cache flushing on rebase workspace --- .../ContentCache/NodesInUserWorkspace.feature | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/Neos.Neos/Tests/Behavior/Features/ContentCache/NodesInUserWorkspace.feature b/Neos.Neos/Tests/Behavior/Features/ContentCache/NodesInUserWorkspace.feature index 783797597fd..1f81e5ed68b 100644 --- a/Neos.Neos/Tests/Behavior/Features/ContentCache/NodesInUserWorkspace.feature +++ b/Neos.Neos/Tests/Behavior/Features/ContentCache/NodesInUserWorkspace.feature @@ -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") + "]"} } """ @@ -245,3 +246,52 @@ Feature: Tests for the ContentCacheFlusher and cache flushing when applied in us """
[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]
""" + + 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: + """ +
firstRender[Text Node at the start of the document]firstRender[Text Node at the end of the document]
+ """ + + 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: + """ +
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]
+ """ \ No newline at end of file From 30382b39d6372431eca2202314d7454c1bfb09bb Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Thu, 19 Sep 2024 12:28:43 +0200 Subject: [PATCH 2/5] TASK: Flush content cache of workspace on a workspace rebase --- .../src/DoctrineDbalContentGraphProjection.php | 11 +++++++---- .../GraphProjectorCatchUpHookForCacheFlushing.php | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php index c0886b1b24b..2cd030ee3bc 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php @@ -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; @@ -166,7 +167,8 @@ public function canHandle(EventInterface $event): bool SubtreeWasTagged::class, SubtreeWasUntagged::class, WorkspaceWasDiscarded::class, - WorkspaceWasPartiallyDiscarded::class + WorkspaceWasPartiallyDiscarded::class, + WorkspaceWasRebased::class ]); } @@ -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))), }; } diff --git a/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php b/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php index 94f66e17ff0..2ee545ee272 100644 --- a/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php +++ b/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php @@ -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; @@ -130,7 +131,8 @@ public function canHandle(EventInterface $event): bool SubtreeWasTagged::class, SubtreeWasUntagged::class, WorkspaceWasDiscarded::class, - WorkspaceWasPartiallyDiscarded::class + WorkspaceWasPartiallyDiscarded::class, + WorkspaceWasRebased::class ]); } @@ -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 ( From 44866e70bdc179f894a505610af3f8138265a6fb Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Thu, 19 Sep 2024 12:30:13 +0200 Subject: [PATCH 3/5] TASK: Improve performance and skip flushing single node aggregates if we will flush the caches for the whole workspace anyway. --- .../GraphProjectorCatchUpHookForCacheFlushing.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php b/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php index 2ee545ee272..ce21cf440bd 100644 --- a/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php +++ b/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php @@ -263,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 (!$this->hasMatchingFlushWorkspaceRequest($request)) { + $this->contentCacheFlusher->flushNodeAggregate($request, CacheFlushingStrategy::IMMEDIATE); + } } $this->flushNodeAggregateRequestsOnAfterCatchUp = []; @@ -272,4 +275,9 @@ public function onAfterCatchUp(): void } $this->flushWorkspaceRequestsOnAfterCatchUp = []; } + + private function hasMatchingFlushWorkspaceRequest(FlushNodeAggregateRequest $request): bool + { + return isset($this->flushWorkspaceRequestsOnAfterCatchUp[$request->workspaceName->value]); + } } From 1f9ad38b0ea36831516648fd64bbf657011ca8b2 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:04:26 +0200 Subject: [PATCH 4/5] TASK: Inline method `hasMatchingFlushWorkspaceRequest` --- .../Cache/GraphProjectorCatchUpHookForCacheFlushing.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php b/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php index ce21cf440bd..321f6308afc 100644 --- a/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php +++ b/Neos.Neos/Classes/Fusion/Cache/GraphProjectorCatchUpHookForCacheFlushing.php @@ -264,7 +264,7 @@ public function onAfterCatchUp(): void { foreach ($this->flushNodeAggregateRequestsOnAfterCatchUp as $request) { // We do not need to flush single node aggregates if we flush the whole workspace anyway. - if (!$this->hasMatchingFlushWorkspaceRequest($request)) { + if (!isset($this->flushWorkspaceRequestsOnAfterCatchUp[$request->workspaceName->value])) { $this->contentCacheFlusher->flushNodeAggregate($request, CacheFlushingStrategy::IMMEDIATE); } } @@ -275,9 +275,4 @@ public function onAfterCatchUp(): void } $this->flushWorkspaceRequestsOnAfterCatchUp = []; } - - private function hasMatchingFlushWorkspaceRequest(FlushNodeAggregateRequest $request): bool - { - return isset($this->flushWorkspaceRequestsOnAfterCatchUp[$request->workspaceName->value]); - } } From 4396f07f00c530afd01ae7d7518473165034d0f2 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Thu, 19 Sep 2024 16:35:21 +0200 Subject: [PATCH 5/5] TASK: Formatting --- .../Features/ContentCache/NodesInUserWorkspace.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Neos.Neos/Tests/Behavior/Features/ContentCache/NodesInUserWorkspace.feature b/Neos.Neos/Tests/Behavior/Features/ContentCache/NodesInUserWorkspace.feature index 1f81e5ed68b..014162ccebf 100644 --- a/Neos.Neos/Tests/Behavior/Features/ContentCache/NodesInUserWorkspace.feature +++ b/Neos.Neos/Tests/Behavior/Features/ContentCache/NodesInUserWorkspace.feature @@ -294,4 +294,5 @@ Feature: Tests for the ContentCacheFlusher and cache flushing when applied in us Then I expect the following Fusion rendering result: """
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]
- """ \ No newline at end of file + """ +