FEATURE: Command to delete stale workspaces#5770
Conversation
skurfuerst
left a comment
There was a problem hiding this comment.
Hey Andreas, awesome change!
two nitpicks, and a question:
does the re-creation of a workspace automatically work already? (If you know, a short pointer to this would be nice <3 )
All the best,
Sebastian
34d8d59 to
e62cb5f
Compare
There was a problem hiding this comment.
Thanks for getting back with this change.
What do you say regarding my previous note:
There is one slight difference to removing and recreating a workspace than to reactivate and deactivate it. The additional neos workspace metadata like title, description, and roles are lost. So in case we hold that information dear we can possibly implement an activation or deactivation on Neos side.
I see we now use $contentRepositoryInstance->handle(DeleteWorkspace::create($workspace)); directly from the outside CommandController and thus leave the Neos MetaData intact. The Neos MetaData though - if kept intact - deserves a new state at Neos\Neos\Domain\Model\WorkspaceClassification possibly like PERSONAL_STALE, or as flag in WorkspaceMetadata. That way when requesting a workspace in createPersonalWorkspaceForUserIfMissing() we better know to expect the workspace not being there and that we have to recreate it.
That also means the WorkspaceService should encapsulate removing a personal workspace and marking it stale. Im not sure what the best api is jet - e.g. if CommandController or WorkspaceService should determine which workspaces to delete, but probably the latter.
(NEW) if the user doesnt write to the workspace for some time we can remove the users workspace
Also i see that you implemented a way to find users that have not logged in and wrote tests :D juhu!. But we can also look into the event store to date the last change of this workspace. Im not sure which is better and as we operate in Neos.Neos both are legal. Looking into the eventstore is obviously a bit more expensive but this is not relevant here. Also using the event store might allow to extend this feature for arbitrary workspaces where we dont have any information like the user login time.
Ill need to think if looking into the eventstore would even tell us the right information;)
Regarding your questions: Yes it does in Neos\Neos\Ui\Controller\BackendController::indexAction |
I am not sure if we gain anything from this state ,or if we rather should make the system "self healing" as it is now.
I would suggest to keep it as it is right now; we can always adjust to the 2nd version later. Regarding the logic move from CommandController to service, I agree :) All the best, |
I tried not to touch the core with this changes at all and instead rely as much as possible on what is already there. Adding a new state like
Agreed, The code was moved and adjusted slightly (I decided against using
I looked into it but were inconclusive if the dates in the eventstore were better. If i remember correctly (it was a few months ago) they did not update on user login, even if the backend was opened. This would mean the personal workspace of a user logging in regularly e.g. to review changes but not making changes on it would be considered stale. This would result in regular deletion and recreation (on login) of this users personal workspace. I am not sure if this scenario is even slightly realistic. But in the end I had the impression I was unable to tell what the implications of using the eventstore data would be, thus decided against using it. |
mhsdesign
left a comment
There was a problem hiding this comment.
i have put my suggestions in a dedicated review pr -
sachera#1 - targeting your fork. Feel free to read through the commits and cherry pick them as you see fit or merge them into your branch as is.
Regarding
Regarding your questions: Yes it does in Neos\Neos\Ui\Controller\BackendController::indexAction createPersonalWorkspaceForUserIfMissing is called in line 160. I do not see any case the workspace is required which is not handled by this.
I know of the requireWorkspace call in the method createPersonalWorkspaceForUserIfMissing which will fail. This is shown in my last commit which provides a failing test.
To fix that ill get to the new metadata state, you wrote:
I tried not to touch the core with this changes at all and instead rely as much as possible on what is already there. Adding a new state like
PERSONAL_STALEwithout need seems to contradict this.
Neos.Neos is core but its not the ESCR core if you know:) It should not be too invasive to add a new state. We only have to test that the workspace module still functions if a user logs in targeting that workspace module and NOT going to the content module first:)
I hope my adjustments sachera#1 make sense:)
… command either way ... these exceptions should not be thrown in a cli controller either way as the output would just confuse users, i hope the `false` check is enough:) ... and cause oddities in php-stan baseline.
…paceService more pure and testable
…d UserId and simplify behat step impl
... because they are now used as return values in classes marked public `@api` and it simplifies logic like checking if a name exists within that set. Also simplify theFollowingUsersDidNotLogInWithinXDays step to be less convoluted and prone to bugs.
…tion to also trigger the garbage collection at the end. Also its improving the API.
…` does not recreate the workspace as promised > The workspace "janedoe-user-workspace" does not exist in content repository "default" this is due to the check in 207
Thank you. The changes look good and I merged them. Maybe I will change some tests to allow ordering of expectations and actual data to differ since I do not consider any specific ordering to be guaranteed by the API and therefore don't want to fix it in the tests.
Good catch. I would have expected it to behave differently but I see why it doesn't. Unfortunately fixing this seems to be more than just recreating the workspace and reusing the metadata: the information which workspace is the base workspace is lost when deleting it. When the test is adjusted to use a root workspace named "live" (instead of "some_root_workspace") it is easy to fix for the case the personal workspace is directly based on the root. Looking at this I also assume the information the stale (deleted) user workspace is based on another is lost when deleting it. Any thoughts on how to tackle this?
At this point i fail to see the gain a new state Also when looking into |
…sers not logged in within a given time
…orkspace is missing (deleted due to being stale) The recreated Workspace is based on the live workspace even if it was based on another workspace before being deleted.
…ensure the database state is clean after each test.
… as base workspace for the recreated user workspace
| * @param string $contentRepository The name of the content repository. (Default: 'default') | ||
| * @param string $dateInterval The time interval a user had to be inactive for its workspaces to be considered stale. (Default: '7 days') | ||
| */ | ||
| public function removeStaleCommand(string $contentRepository = 'default', string $dateInterval = '7 days'): void |
There was a problem hiding this comment.
I would suggest a different naming for the command. The command sounds it removes any stale workspace, but the comment correctly explains its only certain user workspaces. Though a note on their automatic recreation would also be helpful here in the comment.
If we hopefully soonish can extend the removal to other types of workspaces with potential different rules, we have a naming clash. Or what did you think about future future extensions?
Basic Idea
Each Neos account has its own workspace and each workspace its own content stream. These content streams result in a potentially large number of entries in the content repositories hierarchyrelation table, which in turn, will make the fork operation slower.
Core Observation: In a lot of cases only a small amount of these accounts is actually actively used, i.e. have unpublished changes.
The basic idea of this PR is to remove the unnecessary lines from the hierarchyrelation table by deleting "stale" workspaces:
Implementation Details
The feature is exposed through commands in the WorkspaceCommandController:
The command is meant to be used in a cron job or similar to minimize the amount of active workspaces without the need to manually delete workspaces.
Related
pull request #5718 (superseded by this PR)
Checklist
FEATURE|TASK|BUGFIX!!!and have upgrade-instructions