aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos.js')
-rw-r--r--server/controllers/api/videos.js38
1 files changed, 14 insertions, 24 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index 9a50a29be..ebfdb32f9 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -20,6 +20,7 @@ const validatorsSort = validators.sort
20const validatorsVideos = validators.videos 20const validatorsVideos = validators.videos
21const search = middlewares.search 21const search = middlewares.search
22const sort = middlewares.sort 22const sort = middlewares.sort
23const databaseUtils = require('../../helpers/database-utils')
23const utils = require('../../helpers/utils') 24const utils = require('../../helpers/utils')
24 25
25const router = express.Router() 26const router = express.Router()
@@ -111,7 +112,7 @@ function addVideoRetryWrapper (req, res, next) {
111 errorMessage: 'Cannot insert the video with many retries.' 112 errorMessage: 'Cannot insert the video with many retries.'
112 } 113 }
113 114
114 utils.retryWrapper(addVideo, options, function (err) { 115 databaseUtils.retryTransactionWrapper(addVideo, options, function (err) {
115 if (err) return next(err) 116 if (err) return next(err)
116 117
117 // TODO : include Location of the new video -> 201 118 // TODO : include Location of the new video -> 201
@@ -124,11 +125,7 @@ function addVideo (req, res, videoFile, callback) {
124 125
125 waterfall([ 126 waterfall([
126 127
127 function startTransaction (callbackWaterfall) { 128 databaseUtils.startSerializableTransaction,
128 db.sequelize.transaction({ isolationLevel: 'SERIALIZABLE' }).asCallback(function (err, t) {
129 return callbackWaterfall(err, t)
130 })
131 },
132 129
133 function findOrCreateAuthor (t, callbackWaterfall) { 130 function findOrCreateAuthor (t, callbackWaterfall) {
134 const user = res.locals.oauth.token.User 131 const user = res.locals.oauth.token.User
@@ -243,7 +240,7 @@ function updateVideoRetryWrapper (req, res, next) {
243 errorMessage: 'Cannot update the video with many retries.' 240 errorMessage: 'Cannot update the video with many retries.'
244 } 241 }
245 242
246 utils.retryWrapper(updateVideo, options, function (err) { 243 databaseUtils.retryTransactionWrapper(updateVideo, options, function (err) {
247 if (err) return next(err) 244 if (err) return next(err)
248 245
249 // TODO : include Location of the new video -> 201 246 // TODO : include Location of the new video -> 201
@@ -258,11 +255,7 @@ function updateVideo (req, res, finalCallback) {
258 255
259 waterfall([ 256 waterfall([
260 257
261 function startTransaction (callback) { 258 databaseUtils.startSerializableTransaction,
262 db.sequelize.transaction({ isolationLevel: 'SERIALIZABLE' }).asCallback(function (err, t) {
263 return callback(err, t)
264 })
265 },
266 259
267 function findOrCreateTags (t, callback) { 260 function findOrCreateTags (t, callback) {
268 if (videoInfosToUpdate.tags) { 261 if (videoInfosToUpdate.tags) {
@@ -384,19 +377,16 @@ function listVideoAbuses (req, res, next) {
384} 377}
385 378
386function reportVideoAbuseRetryWrapper (req, res, next) { 379function reportVideoAbuseRetryWrapper (req, res, next) {
387 utils.transactionRetryer( 380 const options = {
388 function (callback) { 381 arguments: [ req, res ],
389 return reportVideoAbuse(req, res, callback) 382 errorMessage: 'Cannot report abuse to the video with many retries.'
390 }, 383 }
391 function (err) {
392 if (err) {
393 logger.error('Cannot report abuse to the video with many retries.', { error: err })
394 return next(err)
395 }
396 384
397 return res.type('json').status(204).end() 385 databaseUtils.retryTransactionWrapper(reportVideoAbuse, options, function (err) {
398 } 386 if (err) return next(err)
399 ) 387
388 return res.type('json').status(204).end()
389 })
400} 390}
401 391
402function reportVideoAbuse (req, res, finalCallback) { 392function reportVideoAbuse (req, res, finalCallback) {