aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-12-30 11:51:08 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-12-30 11:51:08 +0100
commit818f7987eba27c59793e2103168b26129c9404f2 (patch)
treec59842f3f3a1d806deb6a096980eee78421d8fd2 /server/controllers/api
parent79066fdf33f79d2d41394f10881e2c226ca26b49 (diff)
downloadPeerTube-818f7987eba27c59793e2103168b26129c9404f2.tar.gz
PeerTube-818f7987eba27c59793e2103168b26129c9404f2.tar.zst
PeerTube-818f7987eba27c59793e2103168b26129c9404f2.zip
Server: optimization for videoGet and videoRemove
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/videos.js28
1 files changed, 5 insertions, 23 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index e5c52a87b..35d6979e5 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -200,7 +200,7 @@ function addVideo (req, res, next) {
200} 200}
201 201
202function updateVideo (req, res, next) { 202function updateVideo (req, res, next) {
203 let videoInstance = res.locals.video 203 const videoInstance = res.locals.video
204 const videoInfosToUpdate = req.body 204 const videoInfosToUpdate = req.body
205 205
206 waterfall([ 206 waterfall([
@@ -275,15 +275,8 @@ function updateVideo (req, res, next) {
275} 275}
276 276
277function getVideo (req, res, next) { 277function getVideo (req, res, next) {
278 db.Video.loadAndPopulateAuthorAndPodAndTags(req.params.id, function (err, video) { 278 const videoInstance = res.locals.video
279 if (err) return next(err) 279 res.json(videoInstance.toFormatedJSON())
280
281 if (!video) {
282 return res.type('json').status(204).end()
283 }
284
285 res.json(video.toFormatedJSON())
286 })
287} 280}
288 281
289function listVideos (req, res, next) { 282function listVideos (req, res, next) {
@@ -295,20 +288,9 @@ function listVideos (req, res, next) {
295} 288}
296 289
297function removeVideo (req, res, next) { 290function removeVideo (req, res, next) {
298 const videoId = req.params.id 291 const videoInstance = res.locals.video
299 292
300 waterfall([ 293 videoInstance.destroy().asCallback(function (err) {
301 function loadVideo (callback) {
302 db.Video.load(videoId, function (err, video) {
303 return callback(err, video)
304 })
305 },
306
307 function deleteVideo (video, callback) {
308 // Informations to other pods will be sent by the afterDestroy video hook
309 video.destroy().asCallback(callback)
310 }
311 ], function andFinally (err) {
312 if (err) { 294 if (err) {
313 logger.error('Errors when removed the video.', { error: err }) 295 logger.error('Errors when removed the video.', { error: err })
314 return next(err) 296 return next(err)