diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-24 13:07:33 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-24 13:38:39 +0200 |
commit | e5565833f62b97f62ea75eba5b479963ae78b873 (patch) | |
tree | 835793ce464f9666b0ceae79f3d278cc4e007b32 /server/lib/activitypub/videos.ts | |
parent | d1a63fc7ac58a1db00d8ca4f43aadba02eb9b084 (diff) | |
download | PeerTube-e5565833f62b97f62ea75eba5b479963ae78b873.tar.gz PeerTube-e5565833f62b97f62ea75eba5b479963ae78b873.tar.zst PeerTube-e5565833f62b97f62ea75eba5b479963ae78b873.zip |
Improve redundancy: add 'min_lifetime' configuration
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r-- | server/lib/activitypub/videos.ts | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 48c0e0a5c..db72ef23c 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -176,7 +176,7 @@ async function getOrCreateVideoAndAccountAndChannel (options: { | |||
176 | syncParam, | 176 | syncParam, |
177 | refreshViews | 177 | refreshViews |
178 | } | 178 | } |
179 | const p = retryTransactionWrapper(refreshVideoIfNeeded, refreshOptions) | 179 | const p = refreshVideoIfNeeded(refreshOptions) |
180 | if (syncParam.refreshVideo === true) videoFromDatabase = await p | 180 | if (syncParam.refreshVideo === true) videoFromDatabase = await p |
181 | 181 | ||
182 | return { video: videoFromDatabase } | 182 | return { video: videoFromDatabase } |
@@ -245,29 +245,37 @@ async function updateVideoFromAP (options: { | |||
245 | generateThumbnailFromUrl(options.video, options.videoObject.icon) | 245 | generateThumbnailFromUrl(options.video, options.videoObject.icon) |
246 | .catch(err => logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err })) | 246 | .catch(err => logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err })) |
247 | 247 | ||
248 | // Remove old video files | 248 | { |
249 | const videoFileDestroyTasks: Bluebird<void>[] = [] | 249 | const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject) |
250 | for (const videoFile of options.video.VideoFiles) { | 250 | const newVideoFiles = videoFileAttributes.map(a => new VideoFileModel(a)) |
251 | videoFileDestroyTasks.push(videoFile.destroy(sequelizeOptions)) | ||
252 | } | ||
253 | await Promise.all(videoFileDestroyTasks) | ||
254 | 251 | ||
255 | const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject) | 252 | // Remove video files that do not exist anymore |
256 | const tasks = videoFileAttributes.map(f => VideoFileModel.create(f, sequelizeOptions)) | 253 | const destroyTasks = options.video.VideoFiles |
257 | await Promise.all(tasks) | 254 | .filter(f => !newVideoFiles.find(newFile => newFile.hasSameUniqueKeysThan(f))) |
255 | .map(f => f.destroy(sequelizeOptions)) | ||
256 | await Promise.all(destroyTasks) | ||
258 | 257 | ||
259 | // Update Tags | 258 | // Update or add other one |
260 | const tags = options.videoObject.tag.map(tag => tag.name) | 259 | const upsertTasks = videoFileAttributes.map(a => VideoFileModel.upsert(a, sequelizeOptions)) |
261 | const tagInstances = await TagModel.findOrCreateTags(tags, t) | 260 | await Promise.all(upsertTasks) |
262 | await options.video.$set('Tags', tagInstances, sequelizeOptions) | 261 | } |
263 | 262 | ||
264 | // Update captions | 263 | { |
265 | await VideoCaptionModel.deleteAllCaptionsOfRemoteVideo(options.video.id, t) | 264 | // Update Tags |
265 | const tags = options.videoObject.tag.map(tag => tag.name) | ||
266 | const tagInstances = await TagModel.findOrCreateTags(tags, t) | ||
267 | await options.video.$set('Tags', tagInstances, sequelizeOptions) | ||
268 | } | ||
266 | 269 | ||
267 | const videoCaptionsPromises = options.videoObject.subtitleLanguage.map(c => { | 270 | { |
268 | return VideoCaptionModel.insertOrReplaceLanguage(options.video.id, c.identifier, t) | 271 | // Update captions |
269 | }) | 272 | await VideoCaptionModel.deleteAllCaptionsOfRemoteVideo(options.video.id, t) |
270 | await Promise.all(videoCaptionsPromises) | 273 | |
274 | const videoCaptionsPromises = options.videoObject.subtitleLanguage.map(c => { | ||
275 | return VideoCaptionModel.insertOrReplaceLanguage(options.video.id, c.identifier, t) | ||
276 | }) | ||
277 | await Promise.all(videoCaptionsPromises) | ||
278 | } | ||
271 | }) | 279 | }) |
272 | 280 | ||
273 | logger.info('Remote video with uuid %s updated', options.videoObject.uuid) | 281 | logger.info('Remote video with uuid %s updated', options.videoObject.uuid) |
@@ -382,7 +390,7 @@ async function refreshVideoIfNeeded (options: { | |||
382 | channel: channelActor.VideoChannel, | 390 | channel: channelActor.VideoChannel, |
383 | updateViews: options.refreshViews | 391 | updateViews: options.refreshViews |
384 | } | 392 | } |
385 | await updateVideoFromAP(updateOptions) | 393 | await retryTransactionWrapper(updateVideoFromAP, updateOptions) |
386 | await syncVideoExternalAttributes(video, videoObject, options.syncParam) | 394 | await syncVideoExternalAttributes(video, videoObject, options.syncParam) |
387 | } catch (err) { | 395 | } catch (err) { |
388 | logger.warn('Cannot refresh video.', { err }) | 396 | logger.warn('Cannot refresh video.', { err }) |