-
-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
!!! FEATURE: AssetUsage as CatchUpHook #5258
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
67a8dae
FEATURE: AssetUsage as CatchUpHook
dlubitz 5b783ef
FEATURE: AssetUsage as CatchUpHook
dlubitz bd2a534
FEATURE: AssetUsage as CatchUpHook
dlubitz b169e3d
TASK: Create database in behat testing context
dlubitz 8fba737
Merge remote-tracking branch 'dlubitz/90/feature/asset-usage-again' i…
dlubitz 0ab0d8c
FEATURE: AssetUsage as CatchUpHook
dlubitz 09232ad
FEATURE: AssetUsage as CatchUpHook
dlubitz 5b90f66
FEATURE: AssetUsage as CatchUpHook
dlubitz 75b34d0
TASK: Cleanup and add code documentation
dlubitz a2b9e63
TASK: Cleanup and add code documentation
dlubitz f83a7fc
TASK: Cleanup and add code documentation
dlubitz b11026d
TASK: Don't use workspaceFinder
dlubitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
Neos.Neos/Classes/AssetUsage/AssetUsageIndexingProcessor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Neos\AssetUsage; | ||
|
||
use Neos\ContentRepository\Core\ContentRepository; | ||
use Neos\ContentRepository\Core\NodeType\NodeTypeName; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\Node; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; | ||
use Neos\ContentRepository\Core\SharedModel\Exception\NodeAggregateCurrentlyDoesNotExist; | ||
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; | ||
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; | ||
use Neos\Neos\AssetUsage\Service\AssetUsageIndexingService; | ||
|
||
readonly class AssetUsageIndexingProcessor | ||
{ | ||
public function __construct( | ||
private AssetUsageIndexingService $assetUsageIndexingService | ||
) { | ||
} | ||
|
||
/** | ||
* @param callable(string $message):void|null $callback | ||
*/ | ||
public function buildIndex(ContentRepository $contentRepository, NodeTypeName $nodeTypeName, callable $callback = null): void | ||
{ | ||
$variationGraph = $contentRepository->getVariationGraph(); | ||
|
||
$workspaceFinder = $contentRepository->getWorkspaceFinder(); | ||
$liveWorkspace = $workspaceFinder->findOneByName(WorkspaceName::forLive()); | ||
if ($liveWorkspace === null) { | ||
throw WorkspaceDoesNotExist::butWasSupposedTo(WorkspaceName::forLive()); | ||
} | ||
|
||
$this->assetUsageIndexingService->pruneIndex($contentRepository->id); | ||
|
||
$workspaces = [$liveWorkspace]; | ||
|
||
$this->dispatchMessage($callback, sprintf('ContentRepository "%s"', $contentRepository->id->value)); | ||
while ($workspaces !== []) { | ||
$workspace = array_shift($workspaces); | ||
|
||
$contentGraph = $contentRepository->getContentGraph($workspace->workspaceName); | ||
$this->dispatchMessage($callback, sprintf(' Workspace: %s', $contentGraph->getWorkspaceName()->value)); | ||
|
||
$dimensionSpacePoints = $variationGraph->getDimensionSpacePoints(); | ||
|
||
$rootNodeAggregate = $contentGraph->findRootNodeAggregateByType( | ||
$nodeTypeName | ||
); | ||
if ($rootNodeAggregate === null) { | ||
$this->dispatchMessage($callback, sprintf(' ERROR: %s', "Root node aggregate was not found.")); | ||
continue; | ||
} | ||
$rootNodeAggregateId = $rootNodeAggregate->nodeAggregateId; | ||
|
||
foreach ($dimensionSpacePoints as $dimensionSpacePoint) { | ||
$this->dispatchMessage($callback, sprintf(' DimensionSpacePoint: %s', $dimensionSpacePoint->toJson())); | ||
|
||
$subgraph = $contentGraph->getSubgraph($dimensionSpacePoint, VisibilityConstraints::withoutRestrictions()); | ||
$childNodes = iterator_to_array($subgraph->findChildNodes($rootNodeAggregateId, FindChildNodesFilter::create())); | ||
|
||
while ($childNodes !== []) { | ||
/** @var Node $childNode */ | ||
$childNode = array_shift($childNodes); | ||
if (!$childNode->originDimensionSpacePoint->equals($childNode->dimensionSpacePoint)) { | ||
continue; | ||
} | ||
$this->assetUsageIndexingService->updateIndex($contentRepository->id, $childNode); | ||
array_push($childNodes, ...iterator_to_array($subgraph->findChildNodes($childNode->aggregateId, FindChildNodesFilter::create()))); | ||
} | ||
} | ||
|
||
array_push($workspaces, ...array_values($workspaceFinder->findByBaseWorkspace($workspace->workspaceName))); | ||
} | ||
} | ||
|
||
private function dispatchMessage(?callable $callback, string $value): void | ||
{ | ||
if ($callback === null) { | ||
return; | ||
} | ||
|
||
$callback($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Neos\AssetUsage; | ||
|
||
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Neos\AssetUsage\Domain\AssetUsageRepository; | ||
use Neos\Neos\AssetUsage\Dto\AssetUsageFilter; | ||
use Neos\Neos\AssetUsage\Dto\AssetUsages; | ||
|
||
/** | ||
* Central authority to look up or remove asset usages in specific a ContentRepository | ||
*/ | ||
#[Flow\Scope('singleton')] | ||
class AssetUsageService | ||
{ | ||
public function __construct( | ||
private readonly AssetUsageRepository $assetUsageRepository, | ||
) { | ||
} | ||
|
||
public function findByFilter(ContentRepositoryId $contentRepositoryId, AssetUsageFilter $filter): AssetUsages | ||
{ | ||
return $this->assetUsageRepository->findUsages($contentRepositoryId, $filter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(how) is that related?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behat tests are not working without this change, as the CatchUpHook expects the doctrine:migrate command to be executed. But it's not when we run the
Neos.ContentRepository.BehavioralTests
.This was not an issue before, as these tests where only relying on the projection tables. But the new CatchUpHook now, gets executed also in these test cases.
https://github.com/neos/neos-development-collection/blob/9.0/.composer.json#L34-L41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is our long standing: you have to do doctrine migrate sometimes problem otherwise it will not work problem that youll fix with the catchup thing as far as i know. see slack: https://neos-project.slack.com/archives/C04PYL8H3/p1727209924914109?thread_ts=1727117857.409749&cid=C04PYL8H3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upps i was mistaken, this is just really similar to this problem: #5005
In #4878 i also discovered that disabling the catchup hooks will speed up the tests ... and as they are just run along without any assertions in the core tests we should consider doing this some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, true. But we need to be able to enable it for the test cases where we test the catchup hook 🤷♂️