From 5e12a48c0eead48916b0e16a0f31c5e92e71925b Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:51:49 +0100 Subject: [PATCH] TASK: Turn full discard also into a no-op if there are no changes --- .../02-DiscardWorkspace.feature | 23 +++++++++++++++++++ .../Feature/WorkspaceCommandHandler.php | 7 ++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Neos.ContentRepository.BehavioralTests/Tests/Behavior/Features/W9-WorkspaceDiscarding/02-DiscardWorkspace.feature b/Neos.ContentRepository.BehavioralTests/Tests/Behavior/Features/W9-WorkspaceDiscarding/02-DiscardWorkspace.feature index 27cc51b7e0b..0e180f7d0dd 100644 --- a/Neos.ContentRepository.BehavioralTests/Tests/Behavior/Features/W9-WorkspaceDiscarding/02-DiscardWorkspace.feature +++ b/Neos.ContentRepository.BehavioralTests/Tests/Behavior/Features/W9-WorkspaceDiscarding/02-DiscardWorkspace.feature @@ -150,3 +150,26 @@ Feature: Workspace discarding - basic functionality | newContentStreamId | "user-cs-two-discarded" | Then workspaces live,user-ws-one,user-ws-two have status UP_TO_DATE + + Scenario: Discard is a no-op if there are no changes (and the workspace is outdated) + And the command SetNodeProperties is executed with payload: + | Key | Value | + | workspaceName | "live" | + | nodeAggregateId | "nody-mc-nodeface" | + | originDimensionSpacePoint | {} | + | propertyValues | {"text": "Modified in live workspace"} | + + And the command DiscardWorkspace is executed with payload: + | Key | Value | + | workspaceName | "user-test" | + | newContentStreamId | "user-cs-two-discarded" | + Then workspaces user-test has status OUTDATED + + Then I expect exactly 1 events to be published on stream with prefix "Workspace:user-test" + + And I am in workspace "user-test" and dimension space point {} + Then I expect node aggregate identifier "nody-mc-nodeface" to lead to node user-cs-identifier;nody-mc-nodeface;{} + And I expect this node to have the following properties: + | Key | Value | + | text | "Original" | + Then I expect the content stream "user-cs-two-discarded" to not exist diff --git a/Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php b/Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php index 34293ff53ef..0cea05dc7e3 100644 --- a/Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php +++ b/Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php @@ -685,7 +685,11 @@ private function handleDiscardWorkspace( $workspace = $this->requireWorkspace($command->workspaceName, $commandHandlingDependencies); $baseWorkspace = $this->requireBaseWorkspace($workspace, $commandHandlingDependencies); - return $this->discardWorkspace( + if (!$this->hasEventsInContentStreamExceptForking(ContentStreamEventStreamName::fromContentStreamId($workspace->currentContentStreamId))) { + return; + } + + yield from $this->discardWorkspace( $workspace, $baseWorkspace, $command->newContentStreamId, @@ -706,7 +710,6 @@ private function discardWorkspace( ContentStreamId $newContentStream, CommandHandlingDependencies $commandHandlingDependencies ): \Generator { - // todo only discard if changes, needs new changes flag on the Workspace model yield $this->forkContentStream( $newContentStream, $baseWorkspace->currentContentStreamId,