From 374b725df52d941af1cf37cf211593340c05206c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 16 Feb 2021 09:42:22 +0100 Subject: Optimize remote thumbnail processing --- server/lib/thumbnail.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'server/lib') diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 55478299c..5d0c9f742 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts @@ -1,5 +1,6 @@ +import chaiJsonSchema = require('chai-json-schema') +import { copy, move } from 'fs-extra' import { join } from 'path' - import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' import { processImage } from '../helpers/image-utils' @@ -69,7 +70,19 @@ function createVideoMiniatureFromUrl (options: { ? null : downloadUrl - const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height }) + // If the thumbnail URL did not change + const existingUrl = existingThumbnail + ? existingThumbnail.fileUrl + : null + + // If the thumbnail URL did not change and has a unique filename (introduced in 3.2), avoid thumbnail processing + const thumbnailUrlChanged = !existingUrl || existingUrl !== downloadUrl || downloadUrl.endsWith(`${video.uuid}.jpg`) + const thumbnailCreator = () => { + if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height }) + + return copy(existingThumbnail.getPath(), ThumbnailModel.buildPath(type, filename)) + } + return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) } -- cgit v1.2.3