mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(files_versions): Catch constraint error on version insertion
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
6680dd4182
commit
30a2e8f9b8
1 changed files with 21 additions and 1 deletions
|
|
@ -228,7 +228,27 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
|
|||
$versionEntity->setSize($file->getSize());
|
||||
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
|
||||
$versionEntity->setMetadata([]);
|
||||
$this->versionsMapper->insert($versionEntity);
|
||||
|
||||
$tries = 1;
|
||||
while ($tries < 5) {
|
||||
try {
|
||||
$this->versionsMapper->insert($versionEntity);
|
||||
/* No errors, get out of the method */
|
||||
return;
|
||||
} catch (\OCP\DB\Exception $e) {
|
||||
if (!in_array($e->getReason(), [
|
||||
\OCP\DB\Exception::REASON_CONSTRAINT_VIOLATION,
|
||||
\OCP\DB\Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION,
|
||||
])
|
||||
) {
|
||||
throw $e;
|
||||
}
|
||||
/* Conflict with another version, increase mtime and try again */
|
||||
$versionEntity->setTimestamp($versionEntity->getTimestamp() + 1);
|
||||
$tries++;
|
||||
$this->logger->warning('Constraint violation while inserting version, retrying with increased timestamp', ['exception' => $e]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateVersionEntity(File $sourceFile, int $revision, array $properties): void {
|
||||
|
|
|
|||
Loading…
Reference in a new issue