mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Prevent duplicated HLS playlist on transcoding
This commit is contained in:
@@ -29,6 +29,8 @@ import {
|
|||||||
} from '../paths'
|
} from '../paths'
|
||||||
import { VideoPathManager } from '../video-path-manager'
|
import { VideoPathManager } from '../video-path-manager'
|
||||||
import { VideoTranscodingProfilesManager } from './default-transcoding-profiles'
|
import { VideoTranscodingProfilesManager } from './default-transcoding-profiles'
|
||||||
|
import { retryTransactionWrapper } from '@server/helpers/database-utils'
|
||||||
|
import { sequelizeTypescript } from '@server/initializers/database'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -309,7 +311,9 @@ async function generateHlsPlaylistCommon (options: {
|
|||||||
await transcodeVOD(transcodeOptions)
|
await transcodeVOD(transcodeOptions)
|
||||||
|
|
||||||
// Create or update the playlist
|
// 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) {
|
if (!playlist.playlistFilename) {
|
||||||
playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive)
|
playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive)
|
||||||
@@ -324,7 +328,11 @@ async function generateHlsPlaylistCommon (options: {
|
|||||||
|
|
||||||
playlist.type = VideoStreamingPlaylistType.HLS
|
playlist.type = VideoStreamingPlaylistType.HLS
|
||||||
|
|
||||||
await playlist.save()
|
await playlist.save({ transaction })
|
||||||
|
|
||||||
|
return playlist
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// Build the new playlist file
|
// Build the new playlist file
|
||||||
const extname = extnameUtil(videoFilename)
|
const extname = extnameUtil(videoFilename)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import memoizee from 'memoizee'
|
import memoizee from 'memoizee'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { Op } from 'sequelize'
|
import { Op, Transaction } from 'sequelize'
|
||||||
import {
|
import {
|
||||||
AllowNull,
|
AllowNull,
|
||||||
BelongsTo,
|
BelongsTo,
|
||||||
@@ -180,19 +180,20 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
|
|||||||
return VideoStreamingPlaylistModel.findByPk(id, options)
|
return VideoStreamingPlaylistModel.findByPk(id, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
static loadHLSPlaylistByVideo (videoId: number): Promise<MStreamingPlaylist> {
|
static loadHLSPlaylistByVideo (videoId: number, transaction?: Transaction): Promise<MStreamingPlaylist> {
|
||||||
const options = {
|
const options = {
|
||||||
where: {
|
where: {
|
||||||
type: VideoStreamingPlaylistType.HLS,
|
type: VideoStreamingPlaylistType.HLS,
|
||||||
videoId
|
videoId
|
||||||
}
|
},
|
||||||
|
transaction
|
||||||
}
|
}
|
||||||
|
|
||||||
return VideoStreamingPlaylistModel.findOne(options)
|
return VideoStreamingPlaylistModel.findOne(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
static async loadOrGenerate (video: MVideo) {
|
static async loadOrGenerate (video: MVideo, transaction?: Transaction) {
|
||||||
let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id)
|
let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id, transaction)
|
||||||
if (!playlist) playlist = new VideoStreamingPlaylistModel()
|
if (!playlist) playlist = new VideoStreamingPlaylistModel()
|
||||||
|
|
||||||
return Object.assign(playlist, { videoId: video.id, Video: video })
|
return Object.assign(playlist, { videoId: video.id, Video: video })
|
||||||
|
|||||||
Reference in New Issue
Block a user