aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-18 12:00:49 +0200
committerChocobozzz <me@florianbigard.com>2018-09-19 09:54:37 +0200
commit627621c1e8d37c33f7b3dd59f4c8907b12c630bc (patch)
tree007e7118f482c543d3898b222b62c185fda4fd2b /server/helpers/custom-validators
parente972e046dbe9b499944c4fab9220eee13e31ac1b (diff)
downloadPeerTube-627621c1e8d37c33f7b3dd59f4c8907b12c630bc.tar.gz
PeerTube-627621c1e8d37c33f7b3dd59f4c8907b12c630bc.tar.zst
PeerTube-627621c1e8d37c33f7b3dd59f4c8907b12c630bc.zip
Optimize SQL requests of watch page API endpoints
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/videos.ts14
1 files changed, 8 insertions, 6 deletions
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
152 return true 152 return true
153} 153}
154 154
155async function isVideoExist (id: string, res: Response) { 155async function isVideoExist (id: string, res: Response, fetchType: 'all' | 'only-video' | 'id' | 'none' = 'all') {
156 let video: VideoModel | null 156 let video: VideoModel | null
157 157
158 if (validator.isInt(id)) { 158 if (fetchType === 'all') {
159 video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id) 159 video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
160 } else { // UUID 160 } else if (fetchType === 'only-video') {
161 video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) 161 video = await VideoModel.load(id)
162 } else if (fetchType === 'id' || fetchType === 'none') {
163 video = await VideoModel.loadOnlyId(id)
162 } 164 }
163 165
164 if (video === null) { 166 if (video === null) {
@@ -169,7 +171,7 @@ async function isVideoExist (id: string, res: Response) {
169 return false 171 return false
170 } 172 }
171 173
172 res.locals.video = video 174 if (fetchType !== 'none') res.locals.video = video
173 return true 175 return true
174} 176}
175 177