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

Minimal yjs based collaboration #2971

Merged
merged 60 commits into from
Jan 31, 2023
Merged

Minimal yjs based collaboration #2971

merged 60 commits into from
Jan 31, 2023

Conversation

max-nextcloud
Copy link
Collaborator

@max-nextcloud max-nextcloud commented Sep 20, 2022

@juliusknorr juliusknorr added this to the Nextcloud 26 milestone Sep 22, 2022
@juliusknorr juliusknorr added enhancement New feature or request 2. developing labels Oct 11, 2022
@max-nextcloud max-nextcloud force-pushed the experiment/minimal-yjs branch from 9cd3d29 to 0b8e260 Compare October 17, 2022 13:12
@max-nextcloud max-nextcloud force-pushed the experiment/minimal-yjs branch from 0b8e260 to 3057169 Compare December 7, 2022 06:58
@cypress
Copy link

cypress bot commented Dec 7, 2022

Passing run #8385 ↗︎

0 132 0 0 Flakiness 0

Details:

Minimal yjs based collaboration
Project: Text Commit: b49ade4770
Status: Passed Duration: 06:41 💡
Started: Jan 31, 2023 9:43 AM Ended: Jan 31, 2023 9:50 AM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@@ -125,11 +124,11 @@ public function createDocument(File $file): Document {

// Do not hard reset if changed from outside since this will throw away possible steps
// This way the user can still resolve conflicts in the editor view
if ($document->getLastSavedVersion() !== $document->getCurrentVersion()) {
$stepsVersion = $this->stepMapper->getLatestVersion($document->getId());
if ($stepsVersion && ($document->getLastSavedVersion() !== $stepsVersion)) {
Copy link
Member

Choose a reason for hiding this comment

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

If we drop the step version that check against the last saved version will no longer work, so maybe we need to find a different approach to determine the collision case.

@max-nextcloud max-nextcloud force-pushed the experiment/minimal-yjs branch 2 times, most recently from 5ab0d4c to 9cae5ea Compare December 12, 2022 11:51
Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

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

First half of the review for backend bits

lib/Db/StepMapper.php Outdated Show resolved Hide resolved
lib/Service/ApiService.php Outdated Show resolved Hide resolved
lib/Service/ApiService.php Show resolved Hide resolved
lib/Service/DocumentService.php Outdated Show resolved Hide resolved
$oldVersion = $document->getCurrentVersion();
$newVersion = $oldVersion + count($steps);
$stepsVersion = $this->stepMapper->getLatestVersion($document->getId());
$newVersion = $stepsVersion + count($steps);
Copy link
Member

Choose a reason for hiding this comment

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

If we get rid of the lock we may want to wrap this in a transaction so that reading the current version, increasing and writing steps is an atomic operation.

Should be easy with https://docs.nextcloud.com/server/latest/developer_manual/basics/storage/database.html#transactions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I created a follow up issue in #3726

@max-nextcloud max-nextcloud force-pushed the experiment/minimal-yjs branch 4 times, most recently from e9f4dd1 to 1e7224f Compare January 25, 2023 17:11
@max-nextcloud
Copy link
Collaborator Author

Locally only sync, attachments and the flaky Links tests are failing (with npx cypress run).

@juliusknorr juliusknorr force-pushed the experiment/minimal-yjs branch from 1e7224f to 4326eb3 Compare January 26, 2023 23:10
@juliusknorr
Copy link
Member

Pushed a bit of polishing for the backend code to make CI happy and a fix for direct editing to pass the initial session data to the web socket polyfill. Let's see what CI says.

@juliusknorr

This comment was marked as resolved.

@juliusknorr

This comment was marked as resolved.

@juliusknorr juliusknorr force-pushed the experiment/minimal-yjs branch 2 times, most recently from 98bffa2 to 0ae0ea0 Compare January 27, 2023 16:10
@juliusknorr
Copy link
Member

@max-nextcloud So far for my week I pushed couple of fixes and polishing. I ended up also refactoring the PollingBackend a bit to clean this up. Cypress tests pass now though there are two draft commits that we should discuss on Monday about on how to best handle that.

  • f232328 It seemed that there was still an issue where longer running sessions ended up playing ping pong with messages which lead to heavy load. I figured out that we may not need to send back steps during the push operations as this was originally more a shortcut to avoid another polling round. I feel this is more stable and also makes more sense to just have one channel where steps get sent from the server to the clients. This was they can also continue to fetch them in order of the database
  • 00879a6 As we no longer store the version of the document the left TODO statement // TODO: figure out when to autosave caused that the files were not saved. In order to have a working branch I pushed this draft commit to always send the documentState and autosaveContent with each sync request, but we should probably be smarter about that.

@max-nextcloud
Copy link
Collaborator Author

@juliushaertl Wow... thanks for looking into this and pushing the pr forward like that!
❤️

@max-nextcloud
Copy link
Collaborator Author

@juliushaertl Given your last commit i wonder what happens if...

  • two users edit the doc
  • it's update on the server through a different mechanis -> conflict
  • one user resolves the conflict

Ideally the conflict would get resolved for the other user as well, right? In particular so they do not pick different strategies.
Is that the case already, or what happens?
Did we account for that in the past?

@juliusknorr
Copy link
Member

Ideally the conflict would get resolved for the other user as well, right? In particular so they do not pick different strategies.
Is that the case already, or what happens?
Did we account for that in the past?

We didn't have any handling for different strategies in the past. My additional commit would already solve this by just moving any resulution to happen trough y.js, so individual users can also undo. One thing that might need further work is to timely propagate the resolved conflict, but I'd not consider that a blocker for the merge as it has been worse before ;)

juliusknorr and others added 15 commits January 31, 2023 09:28
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Max <max@nextcloud.com>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
…flict through force save

Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Max <max@nextcloud.com>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Max <max@nextcloud.com>
Replaying old awareness state will trigger cursor moves
which in turn trigger new awareness messages.

Signed-off-by: Max <max@nextcloud.com>
Signed-off-by: Max <max@nextcloud.com>
Sometimes loading the doc will trigger one sync, sometimes two.
Make sure we always inspect the actual save request
by waiting for two syncs before we trigger and inspect it.

Signed-off-by: Max <max@nextcloud.com>
@max-nextcloud max-nextcloud force-pushed the experiment/minimal-yjs branch from 3f4f352 to 23c9e2b Compare January 31, 2023 08:28
Signed-off-by: Max <max@nextcloud.com>
@max-nextcloud max-nextcloud merged commit a337849 into main Jan 31, 2023
@delete-merged-branch delete-merged-branch bot deleted the experiment/minimal-yjs branch January 31, 2023 11:22
@szaimen
Copy link
Contributor

szaimen commented Jan 31, 2023

🎉🎉🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Y.js backend drop in replacement
6 participants