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
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 @@ -238,8 +238,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