X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=9e02d163f5f52ddf3b39f962ac7fdd8639d3800e;hb=7eba5e1fa81c8e54cb8fe298a96e8070afa50921;hp=1ec8d717e5d4c8592b0bec73c6f2844d6002e818;hpb=e436baf0b00b3ecf3731aeba02437ebe4906ac5f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 1ec8d717e..9e02d163f 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -120,7 +120,7 @@ import { MVideoFormattableDetails, MVideoForUser, MVideoFullLight, - MVideoIdThumbnail, + MVideoIdThumbnail, MVideoImmutable, MVideoThumbnail, MVideoThumbnailBlacklist, MVideoWithAllFiles, @@ -132,6 +132,7 @@ import { MThumbnail } from '../../typings/models/video/thumbnail' import { VideoFile } from '@shared/models/videos/video-file.model' import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' import validator from 'validator' +import { ModelCache } from '@server/models/model-cache' export enum ScopeNames { AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', @@ -1074,6 +1075,11 @@ export class VideoModel extends Model { return undefined } + @BeforeDestroy + static invalidateCache (instance: VideoModel) { + ModelCache.Instance.invalidateCache('video', instance.id) + } + static listLocal (): Bluebird { const query = { where: { @@ -1468,6 +1474,28 @@ export class VideoModel extends Model { ]).findOne(options) } + static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird { + const fun = () => { + const where = buildWhereIdOrUUID(id) + const options = { + attributes: [ + 'id', 'url', 'uuid' + ], + where, + transaction: t + } + + return VideoModel.unscoped().findOne(options) + } + + return ModelCache.Instance.doCache({ + cacheType: 'video-immutable', + key: '' + id, + deleteKey: 'video', + fun + }) + } + static loadWithRights (id: number | string, t?: Transaction): Bluebird { const where = buildWhereIdOrUUID(id) const options = {