Skip to content

Commit

Permalink
TASK: Remove CommandResult::block() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed May 17, 2024
1 parent a857349 commit 81dffe9
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\ContentRepositoryRegistry\Factory\ProjectionCatchUpTrigger\CatchUpTriggerWithSynchronousOption;
use Neos\Flow\Cli\CommandController;
use Neos\Neos\Fusion\Cache\GraphProjectorCatchUpHookForCacheFlushing;

Expand Down Expand Up @@ -47,10 +46,8 @@ public function preparePerformanceTestCommand(int $nodesPerLevel, int $levels):
{
$this->performanceMeasurementService->removeEverything();
$this->outputLine("All removed. Starting to fill.");
CatchUpTriggerWithSynchronousOption::synchronously(
fn() => GraphProjectorCatchUpHookForCacheFlushing::disabled(
fn() => $this->performanceMeasurementService->createNodesForPerformanceTest($nodesPerLevel, $levels)
)
GraphProjectorCatchUpHookForCacheFlushing::disabled(
fn() => $this->performanceMeasurementService->createNodesForPerformanceTest($nodesPerLevel, $levels)
);
}

Expand All @@ -62,9 +59,7 @@ public function preparePerformanceTestCommand(int $nodesPerLevel, int $levels):
public function testPerformanceCommand(): void
{
$time = microtime(true);
CatchUpTriggerWithSynchronousOption::synchronously(
fn() => $this->performanceMeasurementService->forkContentStream()
);
$this->performanceMeasurementService->forkContentStream()

$timeElapsed = microtime(true) - $time;
$this->outputLine('Time: ' . $timeElapsed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public function getContentDimensionsOrderedByPriority(): array
new WorkspaceTitle('Live'),
new WorkspaceDescription('The live workspace'),
ContentStreamId::fromString('live-cs-id')
))->block();
));
$contentRepository->handle(CreateRootNodeAggregateWithNode::create(
WorkspaceName::forLive(),
NodeAggregateId::fromString('lady-eleonode-rootford'),
NodeTypeName::fromString(NodeTypeName::ROOT_NODE_TYPE_NAME)
))->block();
));
$contentRepository->handle(CreateNodeAggregateWithNode::create(
WorkspaceName::forLive(),
NodeAggregateId::fromString('nody-mc-nodeface'),
Expand All @@ -126,14 +126,14 @@ public function getContentDimensionsOrderedByPriority(): array
initialPropertyValues: PropertyValuesToWrite::fromArray([
'title' => 'title'
])
))->block();
));
$contentRepository->handle(CreateWorkspace::create(
WorkspaceName::fromString('user-test'),
WorkspaceName::forLive(),
new WorkspaceTitle('User'),
new WorkspaceDescription('The user workspace'),
ContentStreamId::fromString('user-cs-id')
))->block();
));
for ($i = 0; $i <= 1000; $i++) {
$contentRepository->handle(CreateNodeAggregateWithNode::create(
WorkspaceName::forLive(),
Expand All @@ -144,7 +144,7 @@ public function getContentDimensionsOrderedByPriority(): array
initialPropertyValues: PropertyValuesToWrite::fromArray([
'title' => 'title'
])
))->block();
));
// give the database lock some time to recover
usleep(5000);
}
Expand All @@ -166,7 +166,7 @@ public function whileAWorkspaceIsBeingRebased(): void
try {
$this->contentRepository->handle(RebaseWorkspace::create(
$workspaceName,
)->withRebasedContentStreamId(ContentStreamId::fromString('user-test-rebased')))->block();
)->withRebasedContentStreamId(ContentStreamId::fromString('user-test-rebased')));
} catch (\RuntimeException $runtimeException) {
$exception = $runtimeException;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ public function thenConcurrentCommandsLeadToAnException(): void
PropertyValuesToWrite::fromArray([
'title' => 'title47b'
])
))->block();
));
} catch (\Exception $thrownException) {
$exceptionIsThrownAsExpected
= $thrownException instanceof ContentStreamIsClosed || $thrownException instanceof ConcurrencyException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private function handleCreateWorkspace(
$command->newContentStreamId,
$baseWorkspaceContentGraph->getContentStreamId(),
)
)->block();
);

$events = Events::with(
new WorkspaceWasCreated(
Expand Down Expand Up @@ -205,7 +205,7 @@ private function handleCreateRootWorkspace(
CreateContentStream::create(
$newContentStreamId,
)
)->block();
);

$events = Events::with(
new RootWorkspaceWasCreated(
Expand Down Expand Up @@ -242,15 +242,15 @@ private function handlePublishWorkspace(
$this->publishContentStream(
$workspace->currentContentStreamId,
$baseWorkspace->currentContentStreamId
)?->block();
);

// After publishing a workspace, we need to again fork from Base.
$commandHandlingDependencies->handle(
ForkContentStream::create(
$command->newContentStreamId,
$baseWorkspace->currentContentStreamId,
)
)->block();
);

$streamName = WorkspaceEventStreamName::fromWorkspaceName($command->workspaceName)->getEventStreamName();
$events = Events::with(
Expand Down Expand Up @@ -363,7 +363,7 @@ private function handleRebaseWorkspace(
// 0) close old content stream
$commandHandlingDependencies->handle(
CloseContentStream::create($oldWorkspaceContentStreamId)
)->block();
);

// 1) fork a new content stream
$rebasedContentStreamId = $command->rebasedContentStreamId;
Expand All @@ -372,7 +372,7 @@ private function handleRebaseWorkspace(
$command->rebasedContentStreamId,
$baseWorkspace->currentContentStreamId,
)
)->block();
);

$workspaceStreamName = WorkspaceEventStreamName::fromWorkspaceName($command->workspaceName)->getEventStreamName();
$workspaceContentStreamName = ContentStreamEventStreamName::fromContentStreamId(
Expand All @@ -389,7 +389,7 @@ function () use ($originalCommands, $commandHandlingDependencies, &$commandsThat
foreach ($originalCommands as $sequenceNumber => $originalCommand) {
// We no longer need to adjust commands as the workspace stays the same
try {
$commandHandlingDependencies->handle($originalCommand)->block();
$commandHandlingDependencies->handle($originalCommand);
// if we came this far, we know the command was applied successfully.
} catch (\Exception $e) {
$commandsThatFailed = $commandsThatFailed->add(
Expand Down Expand Up @@ -427,12 +427,12 @@ function () use ($originalCommands, $commandHandlingDependencies, &$commandsThat
$oldWorkspaceContentStreamId,
$oldWorkspaceContentStreamIdState,
)
)->block();
);

// ... remove the newly created one...
$commandHandlingDependencies->handle(RemoveContentStream::create(
$rebasedContentStreamId
))->block();
));

// ...and throw an exception that contains all the information about what exactly failed
throw new WorkspaceRebaseFailed($commandsThatFailed, 'Rebase failed', 1711713880);
Expand Down Expand Up @@ -513,7 +513,7 @@ private function handlePublishIndividualNodesFromWorkspace(
$command->contentStreamIdForMatchingPart,
$baseWorkspace->currentContentStreamId,
)
)->block();
);

try {
// 4) using the new content stream, apply the matching commands
Expand All @@ -531,7 +531,7 @@ function () use ($matchingCommands, $commandHandlingDependencies, $baseWorkspace

$commandHandlingDependencies->handle($matchingCommand->createCopyForWorkspace(
$baseWorkspace->workspaceName,
))->block();
));
}
}
);
Expand All @@ -540,15 +540,15 @@ function () use ($matchingCommands, $commandHandlingDependencies, $baseWorkspace
$this->publishContentStream(
$command->contentStreamIdForMatchingPart,
$baseWorkspace->currentContentStreamId
)?->block();
);

// 6) fork a new content stream, based on the base WS, and apply REST
$commandHandlingDependencies->handle(
ForkContentStream::create(
$command->contentStreamIdForRemainingPart,
$baseWorkspace->currentContentStreamId
)
)->block();
);


// 7) apply REMAINING commands to the workspace's new content stream
Expand All @@ -557,7 +557,7 @@ function () use ($matchingCommands, $commandHandlingDependencies, $baseWorkspace
$command->contentStreamIdForRemainingPart,
function () use ($commandHandlingDependencies, $remainingCommands) {
foreach ($remainingCommands as $remainingCommand) {
$commandHandlingDependencies->handle($remainingCommand)->block();
$commandHandlingDependencies->handle($remainingCommand);
}
}
);
Expand All @@ -568,16 +568,16 @@ function () use ($commandHandlingDependencies, $remainingCommands) {
$oldWorkspaceContentStreamId,
$oldWorkspaceContentStreamIdState,
)
)->block();
);

$commandHandlingDependencies->handle(RemoveContentStream::create(
$command->contentStreamIdForMatchingPart
))->block();
));

try {
$commandHandlingDependencies->handle(RemoveContentStream::create(
$command->contentStreamIdForRemainingPart
))->block();
));
} catch (ContentStreamDoesNotExistYet $contentStreamDoesNotExistYet) {
// in case the exception was thrown before 6), this does not exist
}
Expand Down Expand Up @@ -637,7 +637,7 @@ private function handleDiscardIndividualNodesFromWorkspace(
// 1) close old content stream
$commandHandlingDependencies->handle(
CloseContentStream::create($oldWorkspaceContentStreamId)
)->block();
);

// 2) filter commands, only keeping the ones NOT MATCHING the nodes from the command
// (i.e. the modifications we want to keep)
Expand All @@ -653,7 +653,7 @@ private function handleDiscardIndividualNodesFromWorkspace(
$command->newContentStreamId,
$baseWorkspace->currentContentStreamId,
)
)->block();
);

// 4) using the new content stream, apply the commands to keep
try {
Expand All @@ -671,7 +671,7 @@ function () use ($commandsToKeep, $commandHandlingDependencies, $baseWorkspace):

$commandHandlingDependencies->handle($matchingCommand->createCopyForWorkspace(
$baseWorkspace->workspaceName,
))->block();
));
}
}
);
Expand All @@ -682,19 +682,19 @@ function () use ($commandsToKeep, $commandHandlingDependencies, $baseWorkspace):
$oldWorkspaceContentStreamId,
$oldWorkspaceContentStreamIdState,
)
)->block();
);

$commandHandlingDependencies->handle(RemoveContentStream::create(
$command->newContentStreamId
))->block();
));

throw $exception;
}

// 5) If everything worked, to avoid dangling content streams, we need to remove the old content stream
$commandHandlingDependencies->handle(RemoveContentStream::create(
$oldWorkspaceContentStreamId
))->block();
));

$streamName = WorkspaceEventStreamName::fromWorkspaceName($command->workspaceName)->getEventStreamName();

Expand Down Expand Up @@ -779,7 +779,7 @@ private function handleDiscardWorkspace(
$newContentStream,
$baseWorkspace->currentContentStreamId,
)
)->block();
);

// if we got so far without an Exception, we can switch the Workspace's active Content stream.
$streamName = WorkspaceEventStreamName::fromWorkspaceName($command->workspaceName)->getEventStreamName();
Expand Down Expand Up @@ -824,7 +824,7 @@ private function handleChangeBaseWorkspace(
$command->newContentStreamId,
$baseWorkspace->currentContentStreamId,
)
)->block();
);

$streamName = WorkspaceEventStreamName::fromWorkspaceName($command->workspaceName)->getEventStreamName();
$events = Events::with(
Expand Down Expand Up @@ -855,7 +855,7 @@ private function handleDeleteWorkspace(
RemoveContentStream::create(
$workspace->currentContentStreamId
)
)->block();
);

$events = Events::with(
new WorkspaceWasRemoved(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getOrCreateLiveWorkspace(): Workspace
WorkspaceDescription::fromString('Public live workspace'),
ContentStreamId::create()
)
)->block();
);
$liveWorkspace = $this->contentRepository->getWorkspaceFinder()->findOneByName($liveWorkspaceName);
if (!$liveWorkspace) {
throw new \Exception('Live workspace creation failed', 1699002435);
Expand Down Expand Up @@ -81,7 +81,7 @@ public function getOrCreateRootNodeAggregate(
$workspace->workspaceName,
$rootNodeAggregateId,
$rootNodeTypeName,
))->block();
));
return $rootNodeAggregateId;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function rebaseOutdatedWorkspaces(?RebaseErrorHandlingStrategy $strategy
if ($strategy) {
$rebaseCommand = $rebaseCommand->withErrorHandlingStrategy($strategy);
}
$this->contentRepository->handle($rebaseCommand)->block();
$this->contentRepository->handle($rebaseCommand);
}

return $outdatedWorkspaces;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function executeMigration(ExecuteMigration $command): void
WorkspaceDescription::fromString(''),
$contentStreamForWriting,
)
)->block();
);
/** array $migrationDescription */
$this->executeSubMigrationAndBlock(
$migrationDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function executeGlobalAndBlock(
WorkspaceName $workspaceNameForWriting,
): void {
foreach ($this->globalTransformations as $globalTransformation) {
$globalTransformation->execute($workspaceNameForWriting)->block();
$globalTransformation->execute($workspaceNameForWriting);
}
}

Expand All @@ -104,7 +104,7 @@ public function executeNodeAggregateBasedAndBlock(
ContentStreamId $contentStreamForWriting
): void {
foreach ($this->nodeAggregateBasedTransformations as $nodeAggregateBasedTransformation) {
$nodeAggregateBasedTransformation->execute($nodeAggregate, $workspaceNameForWriting, $contentStreamForWriting)->block();
$nodeAggregateBasedTransformation->execute($nodeAggregate, $workspaceNameForWriting, $contentStreamForWriting);
}
}

Expand All @@ -115,7 +115,7 @@ public function executeNodeBasedAndBlock(
ContentStreamId $contentStreamForWriting
): void {
foreach ($this->nodeBasedTransformations as $nodeBasedTransformation) {
$nodeBasedTransformation->execute($node, $coveredDimensionSpacePoints, $workspaceNameForWriting, $contentStreamForWriting)?->block();
$nodeBasedTransformation->execute($node, $coveredDimensionSpacePoints, $workspaceNameForWriting, $contentStreamForWriting);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function fixError(StructureAdjustment $adjustment): void
$remediation = $adjustment->remediation;
$eventsToPublish = $remediation();
assert($eventsToPublish instanceof EventsToPublish);
$this->eventPersister->publishEvents($eventsToPublish)->block();
$this->eventPersister->publishEvents($eventsToPublish);
}
}
}
Loading

0 comments on commit 81dffe9

Please sign in to comment.