From a8b1b40485145ac1eae513a661d7dd6e0986ce96 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Feb 2021 16:23:19 +0100 Subject: Generate a name for thumbnails Allows aggressive caching --- server/lib/files-cache/videos-preview-cache.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'server/lib/files-cache') diff --git a/server/lib/files-cache/videos-preview-cache.ts b/server/lib/files-cache/videos-preview-cache.ts index d0d4fc5b5..51146d718 100644 --- a/server/lib/files-cache/videos-preview-cache.ts +++ b/server/lib/files-cache/videos-preview-cache.ts @@ -3,6 +3,9 @@ import { FILES_CACHE } from '../../initializers/constants' import { VideoModel } from '../../models/video/video' import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' import { doRequestAndSaveToFile } from '@server/helpers/requests' +import { ThumbnailModel } from '@server/models/video/thumbnail' +import { ThumbnailType } from '@shared/models' +import { logger } from '@server/helpers/logger' class VideosPreviewCache extends AbstractVideoStaticFileCache { @@ -16,13 +19,13 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache { return this.instance || (this.instance = new this()) } - async getFilePathImpl (videoUUID: string) { - const video = await VideoModel.loadByUUID(videoUUID) - if (!video) return undefined + async getFilePathImpl (filename: string) { + const thumbnail = await ThumbnailModel.loadWithVideoByName(filename, ThumbnailType.PREVIEW) + if (!thumbnail) return undefined - if (video.isOwned()) return { isOwned: true, path: video.getPreview().getPath() } + if (thumbnail.Video.isOwned()) return { isOwned: true, path: thumbnail.getPath() } - return this.loadRemoteFile(videoUUID) + return this.loadRemoteFile(thumbnail.Video.uuid) } protected async loadRemoteFile (key: string) { @@ -37,6 +40,8 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache { const remoteUrl = preview.getFileUrl(video) await doRequestAndSaveToFile({ uri: remoteUrl }, destPath) + logger.debug('Fetched remote preview %s to %s.', remoteUrl, destPath) + return { isOwned: false, path: destPath } } } -- cgit v1.2.3