async function updateVideoChannel (req: express.Request, res: express.Response) {
const videoChannelInstance = res.locals.videoChannel
- const videoChannelFieldsSave = videoChannelInstance.toJSON()
const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON())
const videoChannelInfoToUpdate = req.body as VideoChannelUpdate
let doBulkVideoUpdate = false
} catch (err) {
logger.debug('Cannot update the video channel.', { err })
- // Force fields we want to update
// If the transaction is retried, sequelize will think the object has not changed
- // So it will skip the SQL request, even if the last one was ROLLBACKed!
- resetSequelizeInstance(videoChannelInstance, videoChannelFieldsSave)
+ // So we need to restore the previous fields
+ resetSequelizeInstance(videoChannelInstance)
throw err
}
async function updateVideoPlaylist (req: express.Request, res: express.Response) {
const videoPlaylistInstance = res.locals.videoPlaylistFull
- const videoPlaylistFieldsSave = videoPlaylistInstance.toJSON()
const videoPlaylistInfoToUpdate = req.body as VideoPlaylistUpdate
const wasPrivatePlaylist = videoPlaylistInstance.privacy === VideoPlaylistPrivacy.PRIVATE
} catch (err) {
logger.debug('Cannot update the video playlist.', { err })
- // Force fields we want to update
// If the transaction is retried, sequelize will think the object has not changed
- // So it will skip the SQL request, even if the last one was ROLLBACKed!
- resetSequelizeInstance(videoPlaylistInstance, videoPlaylistFieldsSave)
+ // So we need to restore the previous fields
+ resetSequelizeInstance(videoPlaylistInstance)
throw err
}
async function updateVideo (req: express.Request, res: express.Response) {
const videoFromReq = res.locals.videoAll
- const videoFieldsSave = videoFromReq.toJSON()
const oldVideoAuditView = new VideoAuditView(videoFromReq.toFormattedDetailsJSON())
const videoInfoToUpdate: VideoUpdate = req.body
isNewVideo
})
} catch (err) {
- // Force fields we want to update
// If the transaction is retried, sequelize will think the object has not changed
- // So it will skip the SQL request, even if the last one was ROLLBACKed!
- resetSequelizeInstance(videoFromReq, videoFieldsSave)
+ // So we need to restore the previous fields
+ resetSequelizeInstance(videoFromReq)
throw err
} finally {
}
}
-function resetSequelizeInstance (instance: Model<any>, savedFields: object) {
- Object.keys(savedFields).forEach(key => {
- instance[key] = savedFields[key]
- })
+function resetSequelizeInstance <T> (instance: Model<T>) {
+ instance.set(instance.previous())
}
function filterNonExistingModels <T extends { hasSameUniqueKeysThan (other: T): boolean }> (
private accountOrChannel: MAccount | MChannel
- private readonly actorFieldsSave: object
- private readonly accountOrChannelFieldsSave: object
-
constructor (
private readonly actorObject: ActivityPubActor,
private readonly actor: MActorFull
) {
- this.actorFieldsSave = this.actor.toJSON()
-
if (this.actorObject.type === 'Group') this.accountOrChannel = this.actor.VideoChannel
else this.accountOrChannel = this.actor.Account
-
- this.accountOrChannelFieldsSave = this.accountOrChannel.toJSON()
}
async update () {
logger.info('Remote account %s updated', this.actorObject.url)
} catch (err) {
- if (this.actor !== undefined && this.actorFieldsSave !== undefined) {
- resetSequelizeInstance(this.actor, this.actorFieldsSave)
+ if (this.actor !== undefined) {
+ resetSequelizeInstance(this.actor)
}
- if (this.accountOrChannel !== undefined && this.accountOrChannelFieldsSave !== undefined) {
- resetSequelizeInstance(this.accountOrChannel, this.accountOrChannelFieldsSave)
+ if (this.accountOrChannel !== undefined) {
+ resetSequelizeInstance(this.accountOrChannel)
}
// This is just a debug because we will retry the insert
private readonly wasPrivateVideo: boolean
private readonly wasUnlistedVideo: boolean
- private readonly videoFieldsSave: any
-
private readonly oldVideoChannel: MChannelAccountLight
protected lTags: LoggerTagsFn
this.oldVideoChannel = this.video.VideoChannel
- this.videoFieldsSave = this.video.toJSON()
-
this.lTags = loggerTagsFactory('ap', 'video', 'update', video.uuid, video.url)
}
}
private catchUpdateError (err: Error) {
- if (this.video !== undefined && this.videoFieldsSave !== undefined) {
- resetSequelizeInstance(this.video, this.videoFieldsSave)
+ if (this.video !== undefined) {
+ resetSequelizeInstance(this.video)
}
// This is just a debug because we will retry the insert