Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Prevent duplicated HLS playlist on transcoding

Chocobozzz3b0525106d87
diff --git a/server/lib/transcoding/transcoding.ts b/server/lib/transcoding/transcoding.ts
index 9a15f8613f..b64ce6e1fe 100644
--- a/server/lib/transcoding/transcoding.ts
+++ b/server/lib/transcoding/transcoding.ts
@@ -29,6 +29,8 @@ import {
} from '../paths'
import { VideoPathManager } from '../video-path-manager'
import { VideoTranscodingProfilesManager } from './default-transcoding-profiles'
+import { retryTransactionWrapper } from '@server/helpers/database-utils'
+import { sequelizeTypescript } from '@server/initializers/database'
/**
*
@@ -309,22 +311,28 @@ async function generateHlsPlaylistCommon (options: {
await transcodeVOD(transcodeOptions)
// Create or update the playlist
- const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video)
+ const playlist = await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(async transaction => {
+ const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video, transaction)
- if (!playlist.playlistFilename) {
- playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive)
- }
+ if (!playlist.playlistFilename) {
+ playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive)
+ }
- if (!playlist.segmentsSha256Filename) {
- playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(video.isLive)
- }
+ if (!playlist.segmentsSha256Filename) {
+ playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(video.isLive)
+ }
- playlist.p2pMediaLoaderInfohashes = []
- playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION
+ playlist.p2pMediaLoaderInfohashes = []
+ playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION
- playlist.type = VideoStreamingPlaylistType.HLS
+ playlist.type = VideoStreamingPlaylistType.HLS
- await playlist.save()
+ await playlist.save({ transaction })
+
+ return playlist
+ })
+ })
// Build the new playlist file
const extname = extnameUtil(videoFilename)
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts
index 9957ffee3c..2c4dbd8ec7 100644
--- a/server/models/video/video-streaming-playlist.ts
+++ b/server/models/video/video-streaming-playlist.ts
@@ -1,6 +1,6 @@
import memoizee from 'memoizee'
import { join } from 'path'
-import { Op } from 'sequelize'
+import { Op, Transaction } from 'sequelize'
import {
AllowNull,
BelongsTo,
@@ -180,19 +180,20 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
return VideoStreamingPlaylistModel.findByPk(id, options)
}
- static loadHLSPlaylistByVideo (videoId: number): Promise<MStreamingPlaylist> {
+ static loadHLSPlaylistByVideo (videoId: number, transaction?: Transaction): Promise<MStreamingPlaylist> {
const options = {
where: {
type: VideoStreamingPlaylistType.HLS,
videoId
- }
+ },
+ transaction
}
return VideoStreamingPlaylistModel.findOne(options)
}
- static async loadOrGenerate (video: MVideo) {
- let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id)
+ static async loadOrGenerate (video: MVideo, transaction?: Transaction) {
+ let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id, transaction)
if (!playlist) playlist = new VideoStreamingPlaylistModel()
return Object.assign(playlist, { videoId: video.id, Video: video })