diff options
author | Robin Appelman <robin@icewind.nl> | 2020-02-16 02:34:09 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2020-04-09 12:50:59 +0200 |
commit | 7d386872e5f4c5530a936465f71b4e1ea85a565e (patch) | |
tree | 78f98df7273c85953350a0365adbdb2e83613e8d /lib/private/Preview/Generator.php | |
parent | 5cd12cd7c39c2ea156ab35266c9359cdd0f4c070 (diff) | |
download | nextcloud-server-7d386872e5f4c5530a936465f71b4e1ea85a565e.tar.gz nextcloud-server-7d386872e5f4c5530a936465f71b4e1ea85a565e.zip |
optimize batch generation of previews
by allowing the generation of multiple previews at once we save on having to find, open and decode the max-preview for every preview of the same file
the main use case for this is the preview generator app (pr for that comming next)
in my local testing this saves about 25% of time when using the preview generator app
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Preview/Generator.php')
-rw-r--r-- | lib/private/Preview/Generator.php | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index 073001d6788..eedf80d8522 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -138,6 +138,7 @@ class Generator { // Get the max preview and infer the max preview sizes from that $maxPreview = $this->getMaxPreview($previewFolder, $file, $mimeType, $previewVersion); + $maxPreviewImage = null; // only load the image when we need it if ($maxPreview->getSize() === 0) { $maxPreview->delete(); throw new NotFoundException('Max preview size 0, invalid!'); @@ -174,7 +175,11 @@ class Generator { try { $preview = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType(), $previewVersion); } catch (NotFoundException $e) { - $preview = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight, $previewVersion); + if ($maxPreviewImage === null) { + $maxPreviewImage = $this->helper->getImage($maxPreview); + } + + $preview = $this->generatePreview($previewFolder, $maxPreviewImage, $width, $height, $crop, $maxWidth, $maxHeight, $previewVersion); } } catch (\InvalidArgumentException $e) { throw new NotFoundException(); @@ -386,9 +391,8 @@ class Generator { * @throws NotFoundException * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) */ - private function generatePreview(ISimpleFolder $previewFolder, ISimpleFile $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight, $prefix) { - $preview = $this->helper->getImage($maxPreview); - + private function generatePreview(ISimpleFolder $previewFolder, IImage $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight, $prefix) { + $preview = $maxPreview; if (!$preview->valid()) { throw new \InvalidArgumentException('Failed to generate preview, failed to load image'); } @@ -406,13 +410,13 @@ class Generator { $scaleH = $maxHeight / $widthR; $scaleW = $width; } - $preview->preciseResize((int)round($scaleW), (int)round($scaleH)); + $preview = $preview->preciseResizeCopy((int)round($scaleW), (int)round($scaleH)); } $cropX = (int)floor(abs($width - $preview->width()) * 0.5); $cropY = (int)floor(abs($height - $preview->height()) * 0.5); - $preview->crop($cropX, $cropY, $width, $height); + $preview = $preview->cropCopy($cropX, $cropY, $width, $height); } else { - $preview->resize(max($width, $height)); + $preview = $maxPreview->resizeCopy(max($width, $height)); } |