Skip to content
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
10 changes: 1 addition & 9 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ public function sync(Session $session, Document $document, int $version = 0, ?st
// ensure file is still present and accessible
$file = $this->documentService->getFileForSession($session, $shareToken);
$result['readOnly'] = $this->documentService->isReadOnly($file, $shareToken);
$this->documentService->assertNoOutsideConflict($document, $file);
} catch (NotPermittedException|NotFoundException|InvalidPathException $e) {
$this->logger->info($e->getMessage(), ['exception' => $e]);
return new DataResponse([
Expand All @@ -228,16 +227,9 @@ public function sync(Session $session, Document $document, int $version = 0, ?st
return new DataResponse([
'message' => 'Document no longer exists'
], Http::STATUS_NOT_FOUND);
} catch (DocumentSaveConflictException) {
try {
/** @psalm-suppress PossiblyUndefinedVariable */
$result['outsideChange'] = $file->getContent();
} catch (LockedException) {
// Ignore locked exception since it might happen due to an autosave action happening at the same time
}
}

return new DataResponse($result, isset($result['outsideChange']) ? Http::STATUS_CONFLICT : Http::STATUS_OK);
return new DataResponse($result, Http::STATUS_OK);
}

public function save(Session $session, Document $document, int $version, string $autosaveContent, string $documentState, bool $force = false, bool $manualSave = false, ?string $shareToken = null): DataResponse {
Expand Down
7 changes: 6 additions & 1 deletion lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ public function autosave(Document $document, File $file, int $version, string $a

$this->assertNoOutsideConflict($document, $file, $force);

// Abort autosave if already saving.
if ($this->cache->get('document-save-lock-' . $documentId) && $manualSave === false) {
return $document;
}

// 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.
Expand Down Expand Up @@ -427,7 +432,7 @@ public function autosave(Document $document, File $file, int $version, string $a
return $document;
}

$this->cache->set('document-save-lock-' . $documentId, true, 10);
$this->cache->set('document-save-lock-' . $documentId, true, 60);
try {
$this->lockManager->runInScope(new LockContext(
$file,
Expand Down
Loading