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

Ensure document stays consistent with y.js state file #5477

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cypress/e2e/api/SessionApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,15 @@ 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 => {
joining = con
return con
})
.its('state.documentSource')
.should('not.eql', '')
.should('eql', '')
.then(() => joining.close())
.then(() => connection.close())
})
Expand Down
14 changes: 4 additions & 10 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member Author

Choose a reason for hiding this comment

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

This might be another cause of #5420 and is not needed as we only want to load from the file content on the initial session creation

}
$this->logger->debug('Existing document, but state file not found for ' . $file->getId());
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading