diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/transcoding/transcoding.ts | 30 | ||||
-rw-r--r-- | server/models/video/video-streaming-playlist.ts | 11 |
2 files changed, 25 insertions, 16 deletions
diff --git a/server/lib/transcoding/transcoding.ts b/server/lib/transcoding/transcoding.ts index 9a15f8613..b64ce6e1f 100644 --- a/server/lib/transcoding/transcoding.ts +++ b/server/lib/transcoding/transcoding.ts | |||
@@ -29,6 +29,8 @@ import { | |||
29 | } from '../paths' | 29 | } from '../paths' |
30 | import { VideoPathManager } from '../video-path-manager' | 30 | import { VideoPathManager } from '../video-path-manager' |
31 | import { VideoTranscodingProfilesManager } from './default-transcoding-profiles' | 31 | import { VideoTranscodingProfilesManager } from './default-transcoding-profiles' |
32 | import { retryTransactionWrapper } from '@server/helpers/database-utils' | ||
33 | import { sequelizeTypescript } from '@server/initializers/database' | ||
32 | 34 | ||
33 | /** | 35 | /** |
34 | * | 36 | * |
@@ -309,22 +311,28 @@ async function generateHlsPlaylistCommon (options: { | |||
309 | await transcodeVOD(transcodeOptions) | 311 | await transcodeVOD(transcodeOptions) |
310 | 312 | ||
311 | // Create or update the playlist | 313 | // Create or update the playlist |
312 | const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video) | 314 | const playlist = await retryTransactionWrapper(() => { |
315 | return sequelizeTypescript.transaction(async transaction => { | ||
316 | const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video, transaction) | ||
313 | 317 | ||
314 | if (!playlist.playlistFilename) { | 318 | if (!playlist.playlistFilename) { |
315 | playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive) | 319 | playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive) |
316 | } | 320 | } |
317 | 321 | ||
318 | if (!playlist.segmentsSha256Filename) { | 322 | if (!playlist.segmentsSha256Filename) { |
319 | playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(video.isLive) | 323 | playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(video.isLive) |
320 | } | 324 | } |
321 | 325 | ||
322 | playlist.p2pMediaLoaderInfohashes = [] | 326 | playlist.p2pMediaLoaderInfohashes = [] |
323 | playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION | 327 | playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION |
324 | 328 | ||
325 | playlist.type = VideoStreamingPlaylistType.HLS | 329 | playlist.type = VideoStreamingPlaylistType.HLS |
326 | 330 | ||
327 | await playlist.save() | 331 | await playlist.save({ transaction }) |
332 | |||
333 | return playlist | ||
334 | }) | ||
335 | }) | ||
328 | 336 | ||
329 | // Build the new playlist file | 337 | // Build the new playlist file |
330 | const extname = extnameUtil(videoFilename) | 338 | const extname = extnameUtil(videoFilename) |
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 9957ffee3..2c4dbd8ec 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import memoizee from 'memoizee' | 1 | import memoizee from 'memoizee' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { Op } from 'sequelize' | 3 | import { Op, Transaction } from 'sequelize' |
4 | import { | 4 | import { |
5 | AllowNull, | 5 | AllowNull, |
6 | BelongsTo, | 6 | BelongsTo, |
@@ -180,19 +180,20 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi | |||
180 | return VideoStreamingPlaylistModel.findByPk(id, options) | 180 | return VideoStreamingPlaylistModel.findByPk(id, options) |
181 | } | 181 | } |
182 | 182 | ||
183 | static loadHLSPlaylistByVideo (videoId: number): Promise<MStreamingPlaylist> { | 183 | static loadHLSPlaylistByVideo (videoId: number, transaction?: Transaction): Promise<MStreamingPlaylist> { |
184 | const options = { | 184 | const options = { |
185 | where: { | 185 | where: { |
186 | type: VideoStreamingPlaylistType.HLS, | 186 | type: VideoStreamingPlaylistType.HLS, |
187 | videoId | 187 | videoId |
188 | } | 188 | }, |
189 | transaction | ||
189 | } | 190 | } |
190 | 191 | ||
191 | return VideoStreamingPlaylistModel.findOne(options) | 192 | return VideoStreamingPlaylistModel.findOne(options) |
192 | } | 193 | } |
193 | 194 | ||
194 | static async loadOrGenerate (video: MVideo) { | 195 | static async loadOrGenerate (video: MVideo, transaction?: Transaction) { |
195 | let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id) | 196 | let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id, transaction) |
196 | if (!playlist) playlist = new VideoStreamingPlaylistModel() | 197 | if (!playlist) playlist = new VideoStreamingPlaylistModel() |
197 | 198 | ||
198 | return Object.assign(playlist, { videoId: video.id, Video: video }) | 199 | return Object.assign(playlist, { videoId: video.id, Video: video }) |