Skip to content

Commit

Permalink
TASK: Simplify asset usage catchup hook to not optimise partial discard
Browse files Browse the repository at this point in the history
Instead of fine granular updating only the usage references on the nodes that were discarded, well throw away everything and then rely on the reapplied events what is kept.

This is more consistent to how other parts react to publishing like the graph just forks a new content stream and doesnt care about the old data, the change projection behaves similar to the graph.
And for the content cache flusher we had the discussion to use `discardedNodes` but opted against it and do a full flush there as well: neos#5175 (comment)

This change allows us to get rid of the `discardedNodes` property (with dimensions) in the `WorkspaceWasPartiallyDiscarded` event.
  • Loading branch information
mhsdesign committed Nov 30, 2024
1 parent ac2c359 commit e4ad10b
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions Neos.Neos/Classes/AssetUsage/CatchUpHook/AssetUsageCatchUpHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeGeneralizationVariantWasCreated;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeSpecializationVariantWasCreated;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Dto\NodeIdsToPublishOrDiscard;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPartiallyDiscarded;
use Neos\ContentRepository\Core\Projection\CatchUpHookInterface;
Expand Down Expand Up @@ -59,7 +58,6 @@ public function onBeforeEvent(EventInterface $eventInstance, EventEnvelope $even

match ($eventInstance::class) {
NodeAggregateWasRemoved::class => $this->removeNodes($eventInstance->getWorkspaceName(), $eventInstance->nodeAggregateId, $eventInstance->affectedCoveredDimensionSpacePoints),
WorkspaceWasPartiallyDiscarded::class => $this->discardNodes($eventInstance->getWorkspaceName(), $eventInstance->discardedNodes),
default => null
};
}
Expand All @@ -81,7 +79,8 @@ public function onAfterEvent(EventInterface $eventInstance, EventEnvelope $event
NodeGeneralizationVariantWasCreated::class => $this->updateNode($eventInstance->getWorkspaceName(), $eventInstance->nodeAggregateId, $eventInstance->generalizationOrigin->toDimensionSpacePoint()),
NodeSpecializationVariantWasCreated::class => $this->updateNode($eventInstance->getWorkspaceName(), $eventInstance->nodeAggregateId, $eventInstance->specializationOrigin->toDimensionSpacePoint()),
NodePropertiesWereSet::class => $this->updateNode($eventInstance->getWorkspaceName(), $eventInstance->nodeAggregateId, $eventInstance->originDimensionSpacePoint->toDimensionSpacePoint()),
WorkspaceWasDiscarded::class => $this->discardWorkspace($eventInstance->getWorkspaceName()),
WorkspaceWasDiscarded::class,
WorkspaceWasPartiallyDiscarded::class => $this->discardWorkspace($eventInstance->getWorkspaceName()),
DimensionSpacePointWasMoved::class => $this->updateDimensionSpacePoint($eventInstance->getWorkspaceName(), $eventInstance->source, $eventInstance->target),
default => null
};
Expand Down Expand Up @@ -144,22 +143,6 @@ private function discardWorkspace(WorkspaceName $workspaceName): void
$this->assetUsageIndexingService->removeIndexForWorkspace($this->contentRepositoryId, $workspaceName);
}

private function discardNodes(WorkspaceName $workspaceName, NodeIdsToPublishOrDiscard $nodeIds): void
{
foreach ($nodeIds as $nodeId) {
if (!$nodeId->dimensionSpacePoint) {
// NodeAggregateTypeWasChanged and NodeAggregateNameWasChanged don't impact asset usage
continue;
}
$this->assetUsageIndexingService->removeIndexForWorkspaceNameNodeAggregateIdAndDimensionSpacePoint(
$this->contentRepositoryId,
$workspaceName,
$nodeId->nodeAggregateId,
$nodeId->dimensionSpacePoint
);
}
}

private function updateDimensionSpacePoint(WorkspaceName $workspaceName, DimensionSpacePoint $source, DimensionSpacePoint $target): void
{
$this->assetUsageIndexingService->updateDimensionSpacePointInIndex($this->contentRepositoryId, $workspaceName, $source, $target);
Expand Down

0 comments on commit e4ad10b

Please sign in to comment.