Skip to content
Merged
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
22 changes: 20 additions & 2 deletions lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OC\Preview\Db\PreviewMapper;
use OC\Preview\Storage\PreviewFile;
use OC\Preview\Storage\StorageFactory;
use OCP\DB\Exception as DBException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\InvalidPathException;
Expand Down Expand Up @@ -330,9 +331,26 @@ private function getMaxPreview(array $previews, File $file, string $mimeType, ?s
$maxWidth = $this->config->getSystemValueInt('preview_max_x', 4096);
$maxHeight = $this->config->getSystemValueInt('preview_max_y', 4096);

return $this->generateProviderPreview($file, $maxWidth, $maxHeight, false, true, $mimeType, $version);
try {
return $this->generateProviderPreview($file, $maxWidth, $maxHeight, false, true, $mimeType, $version);
} catch (DBException $e) {
if ($e->getReason() === DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
// Fetch again, likely two HTTP requests for the same file were done around the same time
[$file->getId() => $previews] = $this->previewMapper->getAvailablePreviews([$file->getId()]);
foreach ($previews as $preview) {
if ($preview->isMax() && ($version === $preview->getVersion())) {
return $preview;
}
}
}
throw $e;
}
}

/**
* @throws DBException
* @throws NotFoundException
*/
private function generateProviderPreview(File $file, int $width, int $height, bool $crop, bool $max, string $mimeType, ?string $version): Preview {
$previewProviders = $this->previewManager->getProviders();
foreach ($previewProviders as $supportedMimeType => $providers) {
Expand Down Expand Up @@ -550,7 +568,7 @@ private function generatePreview(
* @throws InvalidPathException
* @throws NotFoundException
* @throws NotPermittedException
* @throws \OCP\DB\Exception
* @throws DBException
*/
public function savePreview(Preview $previewEntry, IImage $preview): Preview {
// we need to save to DB first
Expand Down
Loading