Skip to content

Commit

Permalink
Merge pull request #5347 from dlubitz/90/task/improve-asset-removal
Browse files Browse the repository at this point in the history
TASK: Improve removal of asset usages on node removal
  • Loading branch information
kitsunet authored Nov 19, 2024
2 parents a0a0594 + eaeb695 commit dca2d6b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static function fromRawEvent(Event $event): self
$payload = \json_decode($event->data->value, true, 512, JSON_THROW_ON_ERROR);
// unset content stream id as this is overwritten during import
unset($payload['contentStreamId'], $payload['workspaceName']);

return new self(
$event->id->value,
$event->type->value,
Expand All @@ -43,6 +44,7 @@ public static function fromJson(string $json): self
} catch (\JsonException $e) {
throw new \InvalidArgumentException(sprintf('Failed to decode JSON "%s": %s', $json, $e->getMessage()), 1638432979, $e);
}

return new self(
$data['identifier'],
$data['type'],
Expand Down
20 changes: 13 additions & 7 deletions Neos.Neos/Classes/AssetUsage/CatchUpHook/AssetUsageCatchUpHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,23 @@ private function removeNodes(WorkspaceName $workspaceName, NodeAggregateId $node
$contentGraph = $this->contentGraphReadModel->getContentGraph($workspaceName);

foreach ($dimensionSpacePoints as $dimensionSpacePoint) {
$this->assetUsageIndexingService->removeIndexForWorkspaceNameNodeAggregateIdAndDimensionSpacePoint(
$this->contentRepositoryId,
$workspaceName,
$nodeAggregateId,
$dimensionSpacePoint
);

$subgraph = $contentGraph->getSubgraph($dimensionSpacePoint, VisibilityConstraints::withoutRestrictions());
$node = $subgraph->findNodeById($nodeAggregateId);
$descendants = $subgraph->findDescendantNodes($nodeAggregateId, FindDescendantNodesFilter::create());

$nodes = array_merge([$node], iterator_to_array($descendants));

/** @var Node $node */
foreach ($nodes as $node) {
$this->assetUsageIndexingService->removeIndexForNode(
/** @var Node $descendant */
foreach ($descendants as $descendant) {
$this->assetUsageIndexingService->removeIndexForWorkspaceNameNodeAggregateIdAndDimensionSpacePoint(
$this->contentRepositoryId,
$node
$descendant->workspaceName,
$descendant->aggregateId,
$descendant->dimensionSpacePoint
);
}
}
Expand Down
12 changes: 0 additions & 12 deletions Neos.Neos/Classes/AssetUsage/Service/AssetUsageIndexingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,6 @@ public function removeIndexForWorkspaceNameNodeAggregateIdAndDimensionSpacePoint
);
}

public function removeIndexForNode(
ContentRepositoryId $contentRepositoryId,
Node $node
): void {
$this->removeIndexForWorkspaceNameNodeAggregateIdAndDimensionSpacePoint(
$contentRepositoryId,
$node->workspaceName,
$node->aggregateId,
$node->dimensionSpacePoint
);
}

public function removeIndexForWorkspace(
ContentRepositoryId $contentRepositoryId,
WorkspaceName $workspaceName
Expand Down

0 comments on commit dca2d6b

Please sign in to comment.