Skip to content

Commit

Permalink
TASK: Adjust to find* vs get* convention
Browse files Browse the repository at this point in the history
> "all operations which are slow should be named find*", vs. "all operations which operate on already-loaded data should be named get*".

see #5279 (comment)
  • Loading branch information
mhsdesign committed Oct 10, 2024
1 parent db7861f commit c34456b
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Neos.ContentRepository.Core/Classes/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace
return $this->getContentRepositoryReadModel()->findWorkspaceByName($workspaceName);
}

public function getWorkspaces(): Workspaces
public function findWorkspaces(): Workspaces
{
return $this->getContentRepositoryReadModel()->findWorkspaces();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
*/
public function rebaseOutdatedWorkspaces(?RebaseErrorHandlingStrategy $strategy = null): Workspaces
{
$outdatedWorkspaces = $this->contentRepository->getWorkspaces()->filter(
$outdatedWorkspaces = $this->contentRepository->findWorkspaces()->filter(
fn (Workspace $workspace) => $workspace->status === WorkspaceStatus::OUTDATED
);
/** @var Workspace $workspace */
Expand All @@ -52,7 +52,7 @@ public function rebaseOutdatedWorkspaces(?RebaseErrorHandlingStrategy $strategy

public function pruneAll(): void
{
foreach ($this->contentRepository->getWorkspaces() as $workspace) {
foreach ($this->contentRepository->findWorkspaces() as $workspace) {
$streamName = WorkspaceEventStreamName::fromWorkspaceName($workspace->workspaceName)->getEventStreamName();
$this->eventStore->deleteStream($streamName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function iGetTheNodeAtPath(string $serializedNodePath): void
public function iExpectANodeIdentifiedByXToExistInTheContentGraph(string $serializedNodeDiscriminator): void
{
$nodeDiscriminator = NodeDiscriminator::fromShorthand($serializedNodeDiscriminator);
$matchingWorkspace = $this->currentContentRepository->getWorkspaces()->find(
$matchingWorkspace = $this->currentContentRepository->findWorkspaces()->find(
static fn (Workspace $workspace) => $workspace->currentContentStreamId->equals($nodeDiscriminator->contentStreamId)
);
if ($matchingWorkspace === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function buildIndex(ContentRepository $contentRepository, NodeTypeName $n
{
$variationGraph = $contentRepository->getVariationGraph();

$allWorkspaces = $contentRepository->getWorkspaces();
$allWorkspaces = $contentRepository->findWorkspaces();
$liveWorkspace = $contentRepository->findWorkspaceByName(WorkspaceName::forLive());
if ($liveWorkspace === null) {
throw WorkspaceDoesNotExist::butWasSupposedTo(WorkspaceName::forLive());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private function getWorkspaceDependents(ContentRepositoryId $contentRepositoryId
while ($stack !== []) {
/** @var Workspace $workspace */
$workspace = array_shift($stack);
$descendants = $contentRepository->getWorkspaces()->getDependantWorkspaces($workspace->workspaceName);
$descendants = $contentRepository->findWorkspaces()->getDependantWorkspaces($workspace->workspaceName);
foreach ($descendants as $descendant) {
$collectedWorkspaceNames[] = $descendant->workspaceName;
$stack[] = $descendant;
Expand Down
4 changes: 2 additions & 2 deletions Neos.Neos/Classes/Command/WorkspaceCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public function deleteCommand(string $workspace, bool $force = false, string $co
$this->quit(2);
}

$dependentWorkspaces = $contentRepositoryInstance->getWorkspaces()->getDependantWorkspaces($workspaceName);
$dependentWorkspaces = $contentRepositoryInstance->findWorkspaces()->getDependantWorkspaces($workspaceName);
if (!$dependentWorkspaces->isEmpty()) {
$this->outputLine('<error>Workspace "%s" cannot be deleted because the following workspaces are based on it:</error>', [$workspaceName->value]);

Expand Down Expand Up @@ -460,7 +460,7 @@ public function listCommand(string $contentRepository = 'default'): void
{
$contentRepositoryId = ContentRepositoryId::fromString($contentRepository);

$workspaces = $this->contentRepositoryRegistry->get($contentRepositoryId)->getWorkspaces();
$workspaces = $this->contentRepositoryRegistry->get($contentRepositoryId)->findWorkspaces();

if ($workspaces->isEmpty()) {
$this->outputLine('No workspaces found.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function updateSiteAction(Site $site, $newSiteNodeName)
);
}

foreach ($contentRepository->getWorkspaces() as $workspace) {
foreach ($contentRepository->findWorkspaces() as $workspace) {
$siteNodeAggregate = $contentRepository->getContentGraph($workspace->workspaceName)->findChildNodeAggregateByName(
$sitesNode->nodeAggregateId,
$site->getNodeName()->toNodeName()
Expand Down
2 changes: 1 addition & 1 deletion Neos.Neos/Classes/Domain/Service/SiteServiceInternals.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function removeSiteNode(SiteNodeName $siteNodeName): void
);
}

foreach ($this->contentRepository->getWorkspaces() as $workspace) {
foreach ($this->contentRepository->findWorkspaces() as $workspace) {
$contentGraph = $this->contentRepository->getContentGraph($workspace->workspaceName);
$sitesNodeAggregate = $contentGraph->findRootNodeAggregateByType(
NodeTypeNameFactory::forSites()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function getWorkspaceNameAndChildWorkspaceNames(ContentRepository $conte
$workspace = array_shift($stack);
$workspaceNames[] = $workspace->workspaceName;

$stack = array_merge($stack, iterator_to_array($contentRepository->getWorkspaces()->getDependantWorkspaces($workspace->workspaceName)));
$stack = array_merge($stack, iterator_to_array($contentRepository->findWorkspaces()->getDependantWorkspaces($workspace->workspaceName)));
}
}
$this->workspaceRuntimeCache[$contentRepository->id->value][$workspaceName->value] = $workspaceNames;
Expand Down
6 changes: 3 additions & 3 deletions Neos.Neos/Tests/Behavior/Features/Bootstrap/RoutingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function theMatchedNodeShouldBeInContentStreamAndOriginDimension(string $
Assert::assertTrue($matchedNodeAddress->workspaceName->isLive());
Assert::assertSame($nodeAggregateId, $matchedNodeAddress->aggregateId->value);
// todo useless check?
$workspace = $this->currentContentRepository->getWorkspaces()->find(
$workspace = $this->currentContentRepository->findWorkspaces()->find(
fn (Workspace $potentialWorkspace) => $potentialWorkspace->currentContentStreamId->equals(ContentStreamId::fromString($contentStreamId))
);
Assert::assertSame($contentStreamId, $workspace?->currentContentStreamId->value);
Expand Down Expand Up @@ -221,7 +221,7 @@ public function theUrlShouldMatchTheNodeInContentStreamAndDimension(string $url,
Assert::assertEquals(NodeAggregateId::fromString($nodeAggregateId), $matchedNodeAddress->aggregateId, 'Expected nodeAggregateId doesn\'t match.');

// todo use workspace name instead here:
$workspace = $this->currentContentRepository->getWorkspaces()->find(
$workspace = $this->currentContentRepository->findWorkspaces()->find(
fn (Workspace $potentialWorkspace) => $potentialWorkspace->currentContentStreamId->equals(ContentStreamId::fromString($contentStreamId))
);
Assert::assertEquals($workspace->workspaceName, $matchedNodeAddress->workspaceName, 'Expected workspace doesn\'t match.');
Expand Down Expand Up @@ -309,7 +309,7 @@ private function resolveUrl(string $nodeAggregateId, string $contentStreamId, st
if ($this->requestUrl === null) {
$this->iAmOnUrl('/');
}
$workspace = $this->currentContentRepository->getWorkspaces()->find(
$workspace = $this->currentContentRepository->findWorkspaces()->find(
fn (Workspace $potentialWorkspace) => $potentialWorkspace->currentContentStreamId->equals(ContentStreamId::fromString($contentStreamId))
);

Expand Down
8 changes: 4 additions & 4 deletions Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function indexAction(): void
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);

$items = [];
$allWorkspaces = $contentRepository->getWorkspaces();
$allWorkspaces = $contentRepository->findWorkspaces();
foreach ($allWorkspaces as $workspace) {
$workspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepositoryId, $workspace->workspaceName);
$permissions = $this->workspaceService->getWorkspacePermissionsForUser($contentRepositoryId, $workspace->workspaceName, $currentUser);
Expand Down Expand Up @@ -350,7 +350,7 @@ public function deleteAction(WorkspaceName $workspaceName): void
$this->redirect('index');
}

$dependentWorkspaces = $contentRepository->getWorkspaces()->getDependantWorkspaces($workspaceName);
$dependentWorkspaces = $contentRepository->findWorkspaces()->getDependantWorkspaces($workspaceName);
if (!$dependentWorkspaces->isEmpty()) {
$dependentWorkspaceTitles = [];
/** @var Workspace $dependentWorkspace */
Expand Down Expand Up @@ -852,7 +852,7 @@ protected function renderContentChanges(
ContentStreamId $contentStreamIdOfOriginalNode,
ContentRepository $contentRepository,
): array {
$currentWorkspace = $contentRepository->getWorkspaces()->find(
$currentWorkspace = $contentRepository->findWorkspaces()->find(
fn (Workspace $potentialWorkspace) => $potentialWorkspace->currentContentStreamId->equals($contentStreamIdOfOriginalNode)
);
$originalNode = null;
Expand Down Expand Up @@ -1036,7 +1036,7 @@ protected function prepareBaseWorkspaceOptions(
): array {
$user = $this->userService->getCurrentUser();
$baseWorkspaceOptions = [];
$workspaces = $contentRepository->getWorkspaces();
$workspaces = $contentRepository->findWorkspaces();
foreach ($workspaces as $workspace) {
if ($excludedWorkspace !== null) {
if ($workspace->workspaceName->equals($excludedWorkspace)) {
Expand Down

0 comments on commit c34456b

Please sign in to comment.