From 4145c1c68923c13538a5b60d1b384037d0dded9d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 17 Jan 2017 20:38:45 +0100 Subject: Server: transaction refractoring --- server/controllers/api/remote/videos.js | 38 +++++++++++---------------------- 1 file changed, 12 insertions(+), 26 deletions(-) (limited to 'server/controllers/api/remote') diff --git a/server/controllers/api/remote/videos.js b/server/controllers/api/remote/videos.js index e8279fe2e..bfe61a35c 100644 --- a/server/controllers/api/remote/videos.js +++ b/server/controllers/api/remote/videos.js @@ -146,26 +146,19 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) { video.setTags(tagInstances, options).asCallback(function (err) { return callback(err, t) }) - } + }, + + databaseUtils.commitTransaction ], function (err, t) { if (err) { // This is just a debug because we will retry the insert logger.debug('Cannot insert the remote video.', { error: err }) - - // Abort transaction? - if (t) t.rollback() - - return finalCallback(err) + return databaseUtils.rollbackTransaction(err, t, finalCallback) } - // Commit transaction - t.commit().asCallback(function (err) { - if (err) return finalCallback(err) - - logger.info('Remote video %s inserted.', videoToCreateData.name) - return finalCallback(null) - }) + logger.info('Remote video %s inserted.', videoToCreateData.name) + return finalCallback(null) }) } @@ -222,26 +215,19 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) { videoInstance.setTags(tagInstances, options).asCallback(function (err) { return callback(err, t) }) - } + }, + + databaseUtils.commitTransaction ], function (err, t) { if (err) { // This is just a debug because we will retry the insert logger.debug('Cannot update the remote video.', { error: err }) - - // Abort transaction? - if (t) t.rollback() - - return finalCallback(err) + return databaseUtils.rollbackTransaction(err, t, finalCallback) } - // Commit transaction - t.commit().asCallback(function (err) { - if (err) return finalCallback(err) - - logger.info('Remote video %s updated', videoAttributesToUpdate.name) - return finalCallback(null) - }) + logger.info('Remote video %s updated', videoAttributesToUpdate.name) + return finalCallback(null) }) } -- cgit v1.2.3