Skip to content

Commit

Permalink
fix(sync): Save even if versions match
Browse files Browse the repository at this point in the history
Fixes #3404.

Apply saves even if the client and server version match.

The client version only reflects the steps which the client
has received back from the server.
It may leave out the steps the client just send itself.

So if the versions match - save the file to be sure to include changes from the client.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud authored and juliusknorr committed Jun 14, 2023
1 parent 3e7e313 commit abc342d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
15 changes: 0 additions & 15 deletions cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,11 @@ describe('direct editing', function() {
})
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')
cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
cy.wait('@sync', { timeout: 7000 })

cy.get('button.icon-close').click()
cy.wait(`@${closeRequestAlias}`).then(() => {
cy.getFileContent('empty.md').then((content) => {
Expand All @@ -87,17 +82,12 @@ describe('direct editing', function() {
})
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')

cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
cy.wait('@sync', { timeout: 7000 })

cy.get('button.icon-close').click()
cy.wait(`@${closeRequestAlias}`).then(() => {
cy.getFileContent('newfile.md').then((content) => {
Expand All @@ -114,17 +104,12 @@ describe('direct editing', function() {
})
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')

cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
cy.wait('@sync', { timeout: 7000 })

cy.get('button.icon-close').click()
cy.wait(`@${closeRequestAlias}`).then(() => {
cy.getFileContent('empty.txt').then((content) => {
Expand Down
8 changes: 6 additions & 2 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,13 @@ public function autosave(?File $file, int $documentId, int $version, ?string $au
if ($autoSaveDocument === null) {
return $document;
}
// Do not save if version already saved
// Do not save if newer version already saved
// Note that $version is the version of the steps the client has fetched.
// It may have added steps on top of that - so if the versions match we still save.
$stepsVersion = $this->stepMapper->getLatestVersion($documentId);
if (!$force && ($version <= (string)$document->getLastSavedVersion() || $version > (string)$stepsVersion)) {
$savedVersion = $document->getLastSavedVersion();
$outdated = $savedVersion > 0 && $savedVersion > $version;
if (!$force && ($outdated || $version > (string)$stepsVersion)) {
return $document;
}

Expand Down

0 comments on commit abc342d

Please sign in to comment.