From 3f6b6a565dc98a658ec9d8f697252788c0faa46d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 14 Sep 2018 11:05:38 +0200 Subject: Add recently added redundancy strategy --- server/helpers/custom-validators/activitypub/videos.ts | 2 -- 1 file changed, 2 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index f76eba474..8772e74cf 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts @@ -171,5 +171,3 @@ function setRemoteVideoTruncatedContent (video: any) { return true } - - -- cgit v1.2.3 From 627621c1e8d37c33f7b3dd59f4c8907b12c630bc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 18 Sep 2018 12:00:49 +0200 Subject: Optimize SQL requests of watch page API endpoints --- server/helpers/custom-validators/videos.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index edafba6e2..dd207c787 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -152,13 +152,15 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use return true } -async function isVideoExist (id: string, res: Response) { +async function isVideoExist (id: string, res: Response, fetchType: 'all' | 'only-video' | 'id' | 'none' = 'all') { let video: VideoModel | null - if (validator.isInt(id)) { - video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id) - } else { // UUID - video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) + if (fetchType === 'all') { + video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id) + } else if (fetchType === 'only-video') { + video = await VideoModel.load(id) + } else if (fetchType === 'id' || fetchType === 'none') { + video = await VideoModel.loadOnlyId(id) } if (video === null) { @@ -169,7 +171,7 @@ async function isVideoExist (id: string, res: Response) { return false } - res.locals.video = video + if (fetchType !== 'none') res.locals.video = video return true } -- cgit v1.2.3 From 96f29c0f6d2e623fb088e88200934c5df8da9924 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Sep 2018 10:16:44 +0200 Subject: Optimize SQL requests of videos AP endpoints --- server/helpers/custom-validators/videos.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index dd207c787..c9ef8445d 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -152,7 +152,8 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use return true } -async function isVideoExist (id: string, res: Response, fetchType: 'all' | 'only-video' | 'id' | 'none' = 'all') { +export type VideoFetchType = 'all' | 'only-video' | 'id' | 'none' +async function isVideoExist (id: string, res: Response, fetchType: VideoFetchType = 'all') { let video: VideoModel | null if (fetchType === 'all') { -- cgit v1.2.3 From 4157cdb13748cb6e8ce7081d062a8778554cc5a7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Sep 2018 11:16:23 +0200 Subject: Refractor videos AP functions --- server/helpers/custom-validators/videos.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index c9ef8445d..9875c68bd 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -18,6 +18,7 @@ import { exists, isArray, isFileValid } from './misc' import { VideoChannelModel } from '../../models/video/video-channel' import { UserModel } from '../../models/account/user' import * as magnetUtil from 'magnet-uri' +import { fetchVideo, VideoFetchType } from '../video' const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS @@ -152,17 +153,8 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use return true } -export type VideoFetchType = 'all' | 'only-video' | 'id' | 'none' async function isVideoExist (id: string, res: Response, fetchType: VideoFetchType = 'all') { - let video: VideoModel | null - - if (fetchType === 'all') { - video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id) - } else if (fetchType === 'only-video') { - video = await VideoModel.load(id) - } else if (fetchType === 'id' || fetchType === 'none') { - video = await VideoModel.loadOnlyId(id) - } + const video = await fetchVideo(id, fetchType) if (video === null) { res.status(404) -- cgit v1.2.3 From f41d6aacdf3b67e0c8d4e7a599b331d90aa607b7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Sep 2018 17:42:16 +0200 Subject: Fix jobs tests --- server/helpers/custom-validators/video-ownership.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/video-ownership.ts b/server/helpers/custom-validators/video-ownership.ts index aaa0c736b..a7771e07b 100644 --- a/server/helpers/custom-validators/video-ownership.ts +++ b/server/helpers/custom-validators/video-ownership.ts @@ -31,7 +31,7 @@ export function checkUserCanTerminateOwnershipChange ( videoChangeOwnership: VideoChangeOwnershipModel, res: Response ): boolean { - if (videoChangeOwnership.NextOwner.userId === user.Account.userId) { + if (videoChangeOwnership.NextOwner.userId === user.id) { return true } -- cgit v1.2.3