From e268115e6c302a955cd5033c66f9a9a8d72e4179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 13 Mar 2024 17:08:23 +0100 Subject: [PATCH 1/2] fix: Clean up logic to return document state file or file content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- cypress/e2e/api/SessionApi.spec.js | 4 ++-- lib/Service/ApiService.php | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/cypress/e2e/api/SessionApi.spec.js b/cypress/e2e/api/SessionApi.spec.js index 6b8ffe74314..6a102316a71 100644 --- a/cypress/e2e/api/SessionApi.spec.js +++ b/cypress/e2e/api/SessionApi.spec.js @@ -315,7 +315,7 @@ describe('The session Api', function() { }) }) - it('sends initial content if other session is alive but did not push any steps', function() { + it('does not send initial content if other session is alive but did not push any steps', function() { let joining cy.createTextSession(undefined, { filePath: '', shareToken }) .then(con => { @@ -323,7 +323,7 @@ describe('The session Api', function() { return con }) .its('state.documentSource') - .should('not.eql', '') + .should('eql', '') .then(() => joining.close()) .then(() => connection.close()) }) diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index bcd89e4ded6..9d3fd6410e3 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -136,25 +136,19 @@ public function create(?int $fileId = null, ?string $filePath = null, ?string $t $session = $this->sessionService->initSession($document->getId(), $guestName); + $documentState = null; + $content = null; if ($freshSession) { $this->logger->debug('Starting a fresh editing session for ' . $file->getId()); - $documentState = null; $content = $this->loadContent($file); } else { $this->logger->debug('Loading existing session for ' . $file->getId()); - $content = null; try { $stateFile = $this->documentService->getStateFile($document->getId()); $documentState = $stateFile->getContent(); + $this->logger->debug('Existing document, state file loaded ' . $file->getId()); } catch (NotFoundException $e) { - $this->logger->debug('State file not found for ' . $file->getId()); - $documentState = ''; // no state saved yet. - // If there are no steps yet we might still need the content. - $steps = $this->documentService->getSteps($document->getId(), 0); - if (empty($steps)) { - $this->logger->debug('Empty steps, loading content for ' . $file->getId()); - $content = $this->loadContent($file); - } + $this->logger->debug('Existing document, but state file not found for ' . $file->getId()); } } From a63daee740aabc5d5be49f24aa443ed14856daf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 13 Mar 2024 17:08:54 +0100 Subject: [PATCH 2/2] fix: Set base version etag to a unique id per document creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/DocumentService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 39944996a00..f8532b34cf7 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -156,7 +156,7 @@ public function createDocument(File $file): Document { $document->setLastSavedVersion(0); $document->setLastSavedVersionTime($file->getMTime()); $document->setLastSavedVersionEtag($file->getEtag()); - $document->setBaseVersionEtag($file->getEtag()); + $document->setBaseVersionEtag(uniqid()); try { /** @var Document $document */ $document = $this->documentMapper->insert($document);