From 7d14d4d2ca82cc43c93b45bb1f90af975cfbf67c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 31 May 2019 16:30:11 +0200 Subject: Server: Bulk update videos support field --- server/controllers/api/video-channel.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index c98a39be2..81a03a62b 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -19,7 +19,7 @@ import { VideoChannelModel } from '../../models/video/video-channel' import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators' import { sendUpdateActor } from '../../lib/activitypub/send' import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' -import { createVideoChannel } from '../../lib/video-channel' +import { createVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel' import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' import { setAsyncActorKeys } from '../../lib/activitypub' import { AccountModel } from '../../models/account/account' @@ -160,6 +160,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response) const videoChannelFieldsSave = videoChannelInstance.toJSON() const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()) const videoChannelInfoToUpdate = req.body as VideoChannelUpdate + let doBulkVideoUpdate = false try { await sequelizeTypescript.transaction(async t => { @@ -167,9 +168,18 @@ async function updateVideoChannel (req: express.Request, res: express.Response) transaction: t } - if (videoChannelInfoToUpdate.displayName !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.displayName) - if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) - if (videoChannelInfoToUpdate.support !== undefined) videoChannelInstance.set('support', videoChannelInfoToUpdate.support) + if (videoChannelInfoToUpdate.displayName !== undefined) videoChannelInstance.name = videoChannelInfoToUpdate.displayName + if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.description = videoChannelInfoToUpdate.description + + if (videoChannelInfoToUpdate.support !== undefined) { + const oldSupportField = videoChannelInstance.support + videoChannelInstance.support = videoChannelInfoToUpdate.support + + if (videoChannelInfoToUpdate.bulkVideosSupportUpdate === true && oldSupportField !== videoChannelInfoToUpdate.support) { + doBulkVideoUpdate = true + await VideoModel.bulkUpdateSupportField(videoChannelInstance, t) + } + } const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) await sendUpdateActor(videoChannelInstanceUpdated, t) @@ -179,6 +189,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response) new VideoChannelAuditView(videoChannelInstanceUpdated.toFormattedJSON()), oldVideoChannelAuditKeys ) + logger.info('Video channel %s updated.', videoChannelInstance.Actor.url) }) } catch (err) { @@ -192,7 +203,12 @@ async function updateVideoChannel (req: express.Request, res: express.Response) throw err } - return res.type('json').status(204).end() + res.type('json').status(204).end() + + // Don't process in a transaction, and after the response because it could be long + if (doBulkVideoUpdate) { + await federateAllVideosOfChannel(videoChannelInstance) + } } async function removeVideoChannel (req: express.Request, res: express.Response) { -- cgit v1.2.3