From 943e5193905908dd1f2800d8810c635d86e3b28f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 4 Feb 2020 15:45:41 +0100 Subject: Don't refresh videos when processing views It allows us to use a cache --- server/models/video/video.ts | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'server/models/video/video.ts') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 9e02d163f..5964526a9 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -145,6 +145,7 @@ export enum ScopeNames { WITH_USER_HISTORY = 'WITH_USER_HISTORY', WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', WITH_USER_ID = 'WITH_USER_ID', + WITH_IMMUTABLE_ATTRIBUTES = 'WITH_IMMUTABLE_ATTRIBUTES', WITH_THUMBNAILS = 'WITH_THUMBNAILS' } @@ -188,6 +189,9 @@ export type AvailableForListIDsOptions = { } @Scopes(() => ({ + [ScopeNames.WITH_IMMUTABLE_ATTRIBUTES]: { + attributes: [ 'id', 'url', 'uuid', 'remote' ] + }, [ScopeNames.FOR_API]: (options: ForAPIOptions) => { const query: FindOptions = { include: [ @@ -1476,20 +1480,16 @@ export class VideoModel extends Model { static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird { const fun = () => { - const where = buildWhereIdOrUUID(id) - const options = { - attributes: [ - 'id', 'url', 'uuid' - ], - where, + const query = { + where: buildWhereIdOrUUID(id), transaction: t } - return VideoModel.unscoped().findOne(options) + return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query) } return ModelCache.Instance.doCache({ - cacheType: 'video-immutable', + cacheType: 'load-video-immutable-id', key: '' + id, deleteKey: 'video', fun @@ -1559,6 +1559,26 @@ export class VideoModel extends Model { return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) } + static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Bluebird { + const fun = () => { + const query: FindOptions = { + where: { + url + }, + transaction + } + + return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query) + } + + return ModelCache.Instance.doCache({ + cacheType: 'load-video-immutable-url', + key: url, + deleteKey: 'video', + fun + }) + } + static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird { const query: FindOptions = { where: { -- cgit v1.2.3