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
fix(DocumentService): Return 200 steps before saved version in SyncStep2
When replying to a SyncStep1, which the client sends if it detected
a missing step, we now add the 200 steps before the last saved version.

This is done to workaround race conditions where the state with the
missing step got persisted in the document state.

See #7692

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- authored and backportbot[bot] committed Oct 7, 2025
commit 20f39aac63eed6cf1fd3bc019758871da706de72
19 changes: 19 additions & 0 deletions lib/Db/StepMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ public function getLatestVersion(int $documentId): ?int {
return $data['id'];
}

public function getBeforeVersion(int $documentId, int $version, int $offset): int {
$qb = $this->db->getQueryBuilder();
$result = $qb->select('id')
->from($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->andWhere($qb->expr()->lt('id', $qb->createNamedParameter($version)))
->setMaxResults($offset)
->orderBy('id', 'DESC')
->executeQuery();

$rows = $result->fetchAll();
$data = end($rows);
if ($data === false) {
return $version;
}

return $data['id'];
}

public function deleteAll(int $documentId): void {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->getTableName())
Expand Down
5 changes: 3 additions & 2 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ public function addStep(Document $document, Session $session, array $steps, int
$stateFile = $this->getStateFile($documentId);
$documentState = $stateFile->getContent();
$this->logger->debug('Existing document, state file loaded ' . $documentId);
// If there were any queries in the steps, send all steps since last save.
$getStepsSinceVersion = $document->getLastSavedVersion();
// If there were any queries in the steps, send all steps starting 200 steps before last save.
// Adding 200 previous steps to workaround race conditions where state with missing step got persisted in the document state. See #7692
$getStepsSinceVersion = $this->stepMapper->getBeforeVersion($documentId, $document->getLastSavedVersion(), 200);
} catch (NotFoundException $e) {
$this->logger->debug('Existing document, but no state file found for ' . $documentId);
// If there is no state file, include all the steps.
Expand Down
Loading