diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index f2d9ebb790d..1bf5f8b1fec 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -154,8 +154,17 @@ public function createDocument(File $file): Document { $document->setLastSavedVersionTime($file->getFileInfo()->getMtime()); $document->setLastSavedVersionEtag($file->getEtag()); $document->setBaseVersionEtag($file->getEtag()); - $document = $this->documentMapper->insert($document); - $this->cache->set('document-version-'.$document->getId(), 0); + try { + $document = $this->documentMapper->insert($document); + $this->cache->set('document-version-'.$document->getId(), 0); + } catch (Exception $e) { + if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) { + // Document might have been created in the meantime + return $this->documentMapper->find($file->getFileInfo()->getId()); + } + + throw $e; + } return $document; }