aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/remote
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-17 20:38:45 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-17 20:50:45 +0100
commit4145c1c68923c13538a5b60d1b384037d0dded9d (patch)
tree36471645006f47d1118fcba59a4f5d3e84598856 /server/controllers/api/remote
parent98dffd102ef76872f027fedfc55cc0dc824b5bad (diff)
downloadPeerTube-4145c1c68923c13538a5b60d1b384037d0dded9d.tar.gz
PeerTube-4145c1c68923c13538a5b60d1b384037d0dded9d.tar.zst
PeerTube-4145c1c68923c13538a5b60d1b384037d0dded9d.zip
Server: transaction refractoring
Diffstat (limited to 'server/controllers/api/remote')
-rw-r--r--server/controllers/api/remote/videos.js38
1 files changed, 12 insertions, 26 deletions
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) {
146 video.setTags(tagInstances, options).asCallback(function (err) { 146 video.setTags(tagInstances, options).asCallback(function (err) {
147 return callback(err, t) 147 return callback(err, t)
148 }) 148 })
149 } 149 },
150
151 databaseUtils.commitTransaction
150 152
151 ], function (err, t) { 153 ], function (err, t) {
152 if (err) { 154 if (err) {
153 // This is just a debug because we will retry the insert 155 // This is just a debug because we will retry the insert
154 logger.debug('Cannot insert the remote video.', { error: err }) 156 logger.debug('Cannot insert the remote video.', { error: err })
155 157 return databaseUtils.rollbackTransaction(err, t, finalCallback)
156 // Abort transaction?
157 if (t) t.rollback()
158
159 return finalCallback(err)
160 } 158 }
161 159
162 // Commit transaction 160 logger.info('Remote video %s inserted.', videoToCreateData.name)
163 t.commit().asCallback(function (err) { 161 return finalCallback(null)
164 if (err) return finalCallback(err)
165
166 logger.info('Remote video %s inserted.', videoToCreateData.name)
167 return finalCallback(null)
168 })
169 }) 162 })
170} 163}
171 164
@@ -222,26 +215,19 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) {
222 videoInstance.setTags(tagInstances, options).asCallback(function (err) { 215 videoInstance.setTags(tagInstances, options).asCallback(function (err) {
223 return callback(err, t) 216 return callback(err, t)
224 }) 217 })
225 } 218 },
219
220 databaseUtils.commitTransaction
226 221
227 ], function (err, t) { 222 ], function (err, t) {
228 if (err) { 223 if (err) {
229 // This is just a debug because we will retry the insert 224 // This is just a debug because we will retry the insert
230 logger.debug('Cannot update the remote video.', { error: err }) 225 logger.debug('Cannot update the remote video.', { error: err })
231 226 return databaseUtils.rollbackTransaction(err, t, finalCallback)
232 // Abort transaction?
233 if (t) t.rollback()
234
235 return finalCallback(err)
236 } 227 }
237 228
238 // Commit transaction 229 logger.info('Remote video %s updated', videoAttributesToUpdate.name)
239 t.commit().asCallback(function (err) { 230 return finalCallback(null)
240 if (err) return finalCallback(err)
241
242 logger.info('Remote video %s updated', videoAttributesToUpdate.name)
243 return finalCallback(null)
244 })
245 }) 231 })
246} 232}
247 233