Skip to content
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: Deprecate WorkspaceFinder and introduce new API #5279

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

mhsdesign
Copy link
Member

@mhsdesign mhsdesign commented Oct 8, 2024

introduces

  • ContentRepository::findWorkspaces()
  • ContentRepository::findWorkspaceByName()

as well as find and filter methods on the Workspaces collection to replace all functionality of the WorkspaceFinder

This is done as preparation for #5096 which will remove the Workspace projection and thus the finder.

Upgrade instructions

Review instructions

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

@mhsdesign mhsdesign changed the base branch from 9.0 to feature/4726-extract-workspace-metadata-and-user-assignment-to-neos-wip October 8, 2024 16:02
@mhsdesign mhsdesign changed the base branch from feature/4726-extract-workspace-metadata-and-user-assignment-to-neos-wip to feature/4726-extract-workspace-metadata-and-user-assignment-to-neos October 8, 2024 16:02
return $this->getWorkspaceFinder()->findOneByName($workspaceName);
}

public function getWorkspaces(): Workspaces
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo discuss find vs get here. The philosophy to use get was we dont find - eg filter - for anything.
But when we want to use find to signal the the implementation is probably slow (at least uncached) then we should go with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest not to use find = slow and get = fast as a general concept, because it tries to change the meaning of those words.
In this case we don't "find" any workspaces, we just get them all – at least that was my original reasoning :)

However we decide, some doc comment would be nice

Suggested change
public function getWorkspaces(): Workspaces
/**
* Returns all workspaces of this content repository. To limit the set, {@see Workspaces::find()} and {@see Workspaces::filter()} can be used
*/
public function getWorkspaces(): Workspaces

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc our convention is

  • get for what is already there (like in-memory computations, property access)
  • find for everything that has to be fetched from somewhere

Or in short: yes, we decided to go for get* for fast and find* for slow stuff and I'd rather stick to that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im torn in between. getContentGraph for example also does one SQL query to get the currentContentStreamId, though its "get" there ... but im fine with either way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldnt find discuss post to our find* vs get* philosophy but i found a few old artefacts regarding why Node::getParent was renamed to Node::findParent in the old Neos world:

TODO: rename to findParent() because it is a DB operation

and here #2202

adjust TraversableNodeInterface to have proper method namings. Everything which queries something should be called find*; as opposed to get*.

or here #2202 (comment)

$node->findNodePath() sounds weird to me. Why not just getNodePath()?

Because we say: "all operations which are slow should be named find*", vs. "all operations which operate on already-loaded data should be named get*". And fetching a node path is a potentially costly operation.

And in findParent we also definitely dont filter anything still it continues to be named Subgraph::findParentNode.

Though there is one exception Subgraph::findNodePath was eventually renamed to Subgraph::retrieveNodePath with #4090
So it seems retrieveParent or retrieveWorkspaces would also be possibly valid when starting out fresh.

But for now for consistency i guess its a good idea to stick the 6year old philosophy and name it findWorkspaces instead (especially we could consider adding a filter later:)).

Copy link
Member

@bwaidelich bwaidelich Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to avoid confusion: My point was that this kind of "magic meaning" makes sense for a single API, Content(Sub)Graph in this case. I would suggest not to adapt in in general if it leads to weird method names.
But I'm fine with either solution in this case!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really find the distinction between find* and get* hard to grasp, and keep track of. Internals might and can change such that the meaning of find/get is no longer correct, and we cannot change the public API according to our internals. I think this warrants discussion, as I struggled with this naming before as well...

Copy link
Member

@bwaidelich bwaidelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! +1 by reading

@@ -247,6 +244,19 @@ public function getContentGraph(WorkspaceName $workspaceName): ContentGraphInter
return $this->projectionState(ContentGraphFinder::class)->getByWorkspaceName($workspaceName);
}

public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some doc comment would be nice, e.g:

Suggested change
public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace
/**
* Returns the workspace with the given name, or NULL if it does not exist in this content repository
*/
public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace

return $this->getWorkspaceFinder()->findOneByName($workspaceName);
}

public function getWorkspaces(): Workspaces
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest not to use find = slow and get = fast as a general concept, because it tries to change the meaning of those words.
In this case we don't "find" any workspaces, we just get them all – at least that was my original reasoning :)

However we decide, some doc comment would be nice

Suggested change
public function getWorkspaces(): Workspaces
/**
* Returns all workspaces of this content repository. To limit the set, {@see Workspaces::find()} and {@see Workspaces::filter()} can be used
*/
public function getWorkspaces(): Workspaces

@dlubitz
Copy link
Contributor

dlubitz commented Oct 9, 2024

Looks good to me, but tests are failing.

@mhsdesign mhsdesign deleted the branch neos:9.0 October 9, 2024 14:24
@mhsdesign mhsdesign closed this Oct 9, 2024
@mhsdesign mhsdesign reopened this Oct 9, 2024
@mhsdesign mhsdesign changed the base branch from feature/4726-extract-workspace-metadata-and-user-assignment-to-neos to 9.0 October 9, 2024 14:30
@github-actions github-actions bot added the 9.0 label Oct 9, 2024
@mhsdesign mhsdesign force-pushed the task/deprecate--WorkspaceFinder branch from 37734dc to f15eabc Compare October 10, 2024 08:27
> "all operations which are slow should be named find*", vs. "all operations which operate on already-loaded data should be named get*".
@kitsunet kitsunet merged commit bc25ec5 into neos:9.0 Oct 10, 2024
9 checks passed
@mhsdesign mhsdesign deleted the task/deprecate--WorkspaceFinder branch October 10, 2024 17:29
mhsdesign added a commit that referenced this pull request Oct 10, 2024
The review comments were not applied.
@mhsdesign
Copy link
Member Author

Pushed the comment suggestions on 9.0

mhsdesign added a commit that referenced this pull request Oct 10, 2024
> "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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants