Commit 76201839 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Improved generating of thumbnails

parent c9d5e0cc
Pipeline #10061 passed with stage
in 1 minute and 41 seconds
...@@ -19,6 +19,7 @@ package org.genesys.filerepository.service.impl; ...@@ -19,6 +19,7 @@ package org.genesys.filerepository.service.impl;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
...@@ -253,9 +254,9 @@ public class ImageGalleryServiceImpl implements ImageGalleryService { ...@@ -253,9 +254,9 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
imageGallery2.getImages().forEach(repositoryImage -> { imageGallery2.getImages().forEach(repositoryImage -> {
try { try {
final byte[][] cache = new byte[1][]; final byte[][] cache = new byte[1][];
for (int thumbSize: thumbnailSizes) { for (int i = thumbnailSizes.length - 1; i >= 0; i--) {
ensureThumbnail(thumbSize, thumbSize, repositoryImage, () -> { cache[0] = ensureThumbnail(thumbnailSizes[i], thumbnailSizes[i], repositoryImage, () -> {
if (cache[0] != null) { if (cache[0] != null) {
LOG.debug("Using cached image bytes for {}", repositoryImage.getStoragePath()); LOG.debug("Using cached image bytes for {}", repositoryImage.getStoragePath());
return cache[0]; return cache[0];
...@@ -318,7 +319,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService { ...@@ -318,7 +319,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
* @throws InvalidRepositoryPathException if path is messed up * @throws InvalidRepositoryPathException if path is messed up
*/ */
private void ensureThumbnail(final Integer width, final Integer height, final RepositoryImage repositoryImage, final IImageBytesProvider loader) throws IOException, InvalidRepositoryPathException { private byte[] ensureThumbnail(final Integer width, final Integer height, final RepositoryImage repositoryImage, final IImageBytesProvider loader) throws IOException, InvalidRepositoryPathException {
final String filename = getThumbnailFilename(width, height, repositoryImage.getUuid()); final String filename = getThumbnailFilename(width, height, repositoryImage.getUuid());
if (!bytesStorageService.exists(getFullThumbnailsPath(repositoryImage).resolve(filename))) { if (!bytesStorageService.exists(getFullThumbnailsPath(repositoryImage).resolve(filename))) {
...@@ -331,11 +332,12 @@ public class ImageGalleryServiceImpl implements ImageGalleryService { ...@@ -331,11 +332,12 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
LOG.debug("Persisting new thumbnail width={} height={} for image={}", width, height, repositoryImage.getUuid()); LOG.debug("Persisting new thumbnail width={} height={} for image={}", width, height, repositoryImage.getUuid());
bytesStorageService.upsert(getFullThumbnailsPath(repositoryImage).resolve(filename), bytesPng); bytesStorageService.upsert(getFullThumbnailsPath(repositoryImage).resolve(filename), bytesPng);
return bytesPng;
} catch (NullPointerException e) { } catch (NullPointerException e) {
LOG.warn("Error generating thumbnail: {}", e.getMessage()); LOG.warn("Error generating thumbnail: {}", e.getMessage());
} }
} }
return null;
} }
/** /**
...@@ -400,6 +402,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService { ...@@ -400,6 +402,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
} }
public void setThumbnailSizes(int[] thumbnailSizes) { public void setThumbnailSizes(int[] thumbnailSizes) {
Arrays.sort(thumbnailSizes);
this.thumbnailSizes = thumbnailSizes; this.thumbnailSizes = thumbnailSizes;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment