From d9bf974f5df787bbeaab5b04949ca91a2b3ca2a3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 10 Jun 2021 14:43:55 +0200 Subject: Use raw SQL for video get request --- .../shared/abstract-videos-model-query-builder.ts | 239 ++++++++++++++++++ .../sql/shared/abstract-videos-query-builder.ts | 22 ++ server/models/video/sql/shared/video-attributes.ts | 247 +++++++++++++++++++ .../models/video/sql/shared/video-model-builder.ts | 268 +++++++++++++++++++++ 4 files changed, 776 insertions(+) create mode 100644 server/models/video/sql/shared/abstract-videos-model-query-builder.ts create mode 100644 server/models/video/sql/shared/abstract-videos-query-builder.ts create mode 100644 server/models/video/sql/shared/video-attributes.ts create mode 100644 server/models/video/sql/shared/video-model-builder.ts (limited to 'server/models/video/sql/shared') diff --git a/server/models/video/sql/shared/abstract-videos-model-query-builder.ts b/server/models/video/sql/shared/abstract-videos-model-query-builder.ts new file mode 100644 index 000000000..bdf926cbe --- /dev/null +++ b/server/models/video/sql/shared/abstract-videos-model-query-builder.ts @@ -0,0 +1,239 @@ +import { AbstractVideosQueryBuilder } from './abstract-videos-query-builder' +import { VideoAttributes } from './video-attributes' +import { VideoModelBuilder } from './video-model-builder' + +export class AbstractVideosModelQueryBuilder extends AbstractVideosQueryBuilder { + protected attributes: { [key: string]: string } = {} + protected joins: string[] = [] + + protected videoAttributes: VideoAttributes + protected videoModelBuilder: VideoModelBuilder + + constructor (private readonly mode: 'list' | 'get') { + super() + + this.videoAttributes = new VideoAttributes(this.mode) + this.videoModelBuilder = new VideoModelBuilder(this.mode, this.videoAttributes) + } + + protected buildSelect () { + return 'SELECT ' + Object.keys(this.attributes).map(key => { + const value = this.attributes[key] + if (value) return `${key} AS ${value}` + + return key + }).join(', ') + } + + protected includeChannels () { + this.joins.push( + 'INNER JOIN "videoChannel" AS "VideoChannel" ON "video"."channelId" = "VideoChannel"."id"', + 'INNER JOIN "actor" AS "VideoChannel->Actor" ON "VideoChannel"."actorId" = "VideoChannel->Actor"."id"', + + 'LEFT OUTER JOIN "server" AS "VideoChannel->Actor->Server" ON "VideoChannel->Actor"."serverId" = "VideoChannel->Actor->Server"."id"', + + 'LEFT OUTER JOIN "actorImage" AS "VideoChannel->Actor->Avatar" ' + + 'ON "VideoChannel->Actor"."avatarId" = "VideoChannel->Actor->Avatar"."id"' + ) + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('VideoChannel', this.videoAttributes.getChannelAttributes()), + ...this.buildActorInclude('VideoChannel->Actor'), + ...this.buildAvatarInclude('VideoChannel->Actor->Avatar'), + ...this.buildServerInclude('VideoChannel->Actor->Server') + } + } + + protected includeAccounts () { + this.joins.push( + 'INNER JOIN "account" AS "VideoChannel->Account" ON "VideoChannel"."accountId" = "VideoChannel->Account"."id"', + 'INNER JOIN "actor" AS "VideoChannel->Account->Actor" ON "VideoChannel->Account"."actorId" = "VideoChannel->Account->Actor"."id"', + + 'LEFT OUTER JOIN "server" AS "VideoChannel->Account->Actor->Server" ' + + 'ON "VideoChannel->Account->Actor"."serverId" = "VideoChannel->Account->Actor->Server"."id"', + + 'LEFT OUTER JOIN "actorImage" AS "VideoChannel->Account->Actor->Avatar" ' + + 'ON "VideoChannel->Account->Actor"."avatarId" = "VideoChannel->Account->Actor->Avatar"."id"' + ) + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('VideoChannel->Account', this.videoAttributes.getAccountAttributes()), + ...this.buildActorInclude('VideoChannel->Account->Actor'), + ...this.buildAvatarInclude('VideoChannel->Account->Actor->Avatar'), + ...this.buildServerInclude('VideoChannel->Account->Actor->Server') + } + } + + protected includeThumbnails () { + this.joins.push('LEFT OUTER JOIN "thumbnail" AS "Thumbnails" ON "video"."id" = "Thumbnails"."videoId"') + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('Thumbnails', this.videoAttributes.getThumbnailAttributes()) + } + } + + protected includeFiles () { + this.joins.push( + 'LEFT JOIN "videoFile" AS "VideoFiles" ON "VideoFiles"."videoId" = "video"."id"', + + 'LEFT JOIN "videoStreamingPlaylist" AS "VideoStreamingPlaylists" ON "VideoStreamingPlaylists"."videoId" = "video"."id"', + + 'LEFT JOIN "videoFile" AS "VideoStreamingPlaylists->VideoFiles" ' + + 'ON "VideoStreamingPlaylists->VideoFiles"."videoStreamingPlaylistId" = "VideoStreamingPlaylists"."id"' + ) + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('VideoFiles', this.videoAttributes.getFileAttributes()), + + ...this.buildAttributesObject('VideoStreamingPlaylists', this.videoAttributes.getStreamingPlaylistAttributes()), + ...this.buildAttributesObject('VideoStreamingPlaylists->VideoFiles', this.videoAttributes.getFileAttributes()) + } + } + + protected includeUserHistory (userId: number) { + this.joins.push( + 'LEFT OUTER JOIN "userVideoHistory" ' + + 'ON "video"."id" = "userVideoHistory"."videoId" AND "userVideoHistory"."userId" = :userVideoHistoryId' + ) + + this.replacements.userVideoHistoryId = userId + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('userVideoHistory', this.videoAttributes.getUserHistoryAttributes()) + } + } + + protected includePlaylist (playlistId: number) { + this.joins.push( + 'INNER JOIN "videoPlaylistElement" as "VideoPlaylistElement" ON "videoPlaylistElement"."videoId" = "video"."id" ' + + 'AND "VideoPlaylistElement"."videoPlaylistId" = :videoPlaylistId' + ) + + this.replacements.videoPlaylistId = playlistId + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('VideoPlaylistElement', this.videoAttributes.getPlaylistAttributes()) + } + } + + protected includeTags () { + this.joins.push( + 'LEFT OUTER JOIN (' + + '"videoTag" AS "Tags->VideoTagModel" INNER JOIN "tag" AS "Tags" ON "Tags"."id" = "Tags->VideoTagModel"."tagId"' + + ') ' + + 'ON "video"."id" = "Tags->VideoTagModel"."videoId"' + ) + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('Tags', this.videoAttributes.getTagAttributes()), + ...this.buildAttributesObject('Tags->VideoTagModel', this.videoAttributes.getVideoTagAttributes()) + } + } + + protected includeBlacklisted () { + this.joins.push( + 'LEFT OUTER JOIN "videoBlacklist" AS "VideoBlacklist" ON "video"."id" = "VideoBlacklist"."videoId"' + ) + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('VideoBlacklist', this.videoAttributes.getBlacklistedAttributes()) + } + } + + protected includeScheduleUpdate () { + this.joins.push( + 'LEFT OUTER JOIN "scheduleVideoUpdate" AS "ScheduleVideoUpdate" ON "video"."id" = "ScheduleVideoUpdate"."videoId"' + ) + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('ScheduleVideoUpdate', this.videoAttributes.getScheduleUpdateAttributes()) + } + } + + protected includeLive () { + this.joins.push( + 'LEFT OUTER JOIN "videoLive" AS "VideoLive" ON "video"."id" = "VideoLive"."videoId"' + ) + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('VideoLive', this.videoAttributes.getLiveAttributes()) + } + } + + protected includeTrackers () { + this.joins.push( + 'LEFT OUTER JOIN (' + + '"videoTracker" AS "Trackers->VideoTrackerModel" ' + + 'INNER JOIN "tracker" AS "Trackers" ON "Trackers"."id" = "Trackers->VideoTrackerModel"."trackerId"' + + ') ON "video"."id" = "Trackers->VideoTrackerModel"."videoId"' + ) + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('Trackers', this.videoAttributes.getTrackerAttributes()), + ...this.buildAttributesObject('Trackers->VideoTrackerModel', this.videoAttributes.getVideoTrackerAttributes()) + } + } + + protected includeRedundancies () { + this.joins.push( + 'LEFT OUTER JOIN "videoRedundancy" AS "VideoStreamingPlaylists->RedundancyVideos" ' + + 'ON "VideoStreamingPlaylists"."id" = "VideoStreamingPlaylists->RedundancyVideos"."videoStreamingPlaylistId"', + + 'LEFT OUTER JOIN "videoRedundancy" AS "VideoFiles->RedundancyVideos" ON ' + + '"VideoFiles"."id" = "VideoFiles->RedundancyVideos"."videoFileId"' + ) + + this.attributes = { + ...this.attributes, + + ...this.buildAttributesObject('VideoFiles->RedundancyVideos', this.videoAttributes.getRedundancyAttributes()), + ...this.buildAttributesObject('VideoStreamingPlaylists->RedundancyVideos', this.videoAttributes.getRedundancyAttributes()) + } + } + + protected buildActorInclude (prefixKey: string) { + return this.buildAttributesObject(prefixKey, this.videoAttributes.getActorAttributes()) + } + + protected buildAvatarInclude (prefixKey: string) { + return this.buildAttributesObject(prefixKey, this.videoAttributes.getAvatarAttributes()) + } + + protected buildServerInclude (prefixKey: string) { + return this.buildAttributesObject(prefixKey, this.videoAttributes.getServerAttributes()) + } + + protected buildAttributesObject (prefixKey: string, attributeKeys: string[]) { + const result: { [id: string]: string} = {} + + const prefixValue = prefixKey.replace(/->/g, '.') + + for (const attribute of attributeKeys) { + result[`"${prefixKey}"."${attribute}"`] = `"${prefixValue}.${attribute}"` + } + + return result + } +} diff --git a/server/models/video/sql/shared/abstract-videos-query-builder.ts b/server/models/video/sql/shared/abstract-videos-query-builder.ts new file mode 100644 index 000000000..01694e691 --- /dev/null +++ b/server/models/video/sql/shared/abstract-videos-query-builder.ts @@ -0,0 +1,22 @@ +import { QueryTypes, Sequelize, Transaction } from 'sequelize' +import { logger } from '@server/helpers/logger' + +export class AbstractVideosQueryBuilder { + protected sequelize: Sequelize + + protected query: string + protected replacements: any = {} + + protected runQuery (transaction?: Transaction, nest?: boolean) { + logger.debug('Running videos query.', { query: this.query, replacements: this.replacements }) + + const options = { + transaction, + replacements: this.replacements, + type: QueryTypes.SELECT as QueryTypes.SELECT, + nest + } + + return this.sequelize.query(this.query, options) + } +} diff --git a/server/models/video/sql/shared/video-attributes.ts b/server/models/video/sql/shared/video-attributes.ts new file mode 100644 index 000000000..1a1650dc7 --- /dev/null +++ b/server/models/video/sql/shared/video-attributes.ts @@ -0,0 +1,247 @@ +export class VideoAttributes { + + constructor (readonly mode: 'get' | 'list') { + + } + + getChannelAttributes () { + let attributeKeys = [ + 'id', + 'name', + 'description', + 'actorId' + ] + + if (this.mode === 'get') { + attributeKeys = attributeKeys.concat([ + 'support', + 'createdAt', + 'updatedAt' + ]) + } + + return attributeKeys + } + + getAccountAttributes () { + let attributeKeys = [ 'id', 'name', 'actorId' ] + + if (this.mode === 'get') { + attributeKeys = attributeKeys.concat([ + 'description', + 'createdAt', + 'updatedAt' + ]) + } + + return attributeKeys + } + + getThumbnailAttributes () { + let attributeKeys = [ 'id', 'type', 'filename' ] + + if (this.mode === 'get') { + attributeKeys = attributeKeys.concat([ + 'height', + 'width', + 'fileUrl', + 'automaticallyGenerated', + 'videoId', + 'videoPlaylistId', + 'createdAt', + 'updatedAt' + ]) + } + + return attributeKeys + } + + getFileAttributes () { + return [ + 'id', + 'createdAt', + 'updatedAt', + 'resolution', + 'size', + 'extname', + 'filename', + 'fileUrl', + 'torrentFilename', + 'torrentUrl', + 'infoHash', + 'fps', + 'metadataUrl', + 'videoStreamingPlaylistId', + 'videoId' + ] + } + + getStreamingPlaylistAttributes () { + let playlistKeys = [ 'id', 'playlistUrl', 'type' ] + + if (this.mode === 'get') { + playlistKeys = playlistKeys.concat([ + 'p2pMediaLoaderInfohashes', + 'p2pMediaLoaderPeerVersion', + 'segmentsSha256Url', + 'videoId', + 'createdAt', + 'updatedAt' + ]) + } + + return playlistKeys + } + + getUserHistoryAttributes () { + return [ 'id', 'currentTime' ] + } + + getPlaylistAttributes () { + return [ + 'createdAt', + 'updatedAt', + 'url', + 'position', + 'startTimestamp', + 'stopTimestamp', + 'videoPlaylistId' + ] + } + + getTagAttributes () { + return [ 'id', 'name' ] + } + + getVideoTagAttributes () { + return [ 'videoId', 'tagId', 'createdAt', 'updatedAt' ] + } + + getBlacklistedAttributes () { + return [ 'id', 'reason', 'unfederated' ] + } + + getScheduleUpdateAttributes () { + return [ + 'id', + 'updateAt', + 'privacy', + 'videoId', + 'createdAt', + 'updatedAt' + ] + } + + getLiveAttributes () { + return [ + 'id', + 'streamKey', + 'saveReplay', + 'permanentLive', + 'videoId', + 'createdAt', + 'updatedAt' + ] + } + + getTrackerAttributes () { + return [ 'id', 'url' ] + } + + getVideoTrackerAttributes () { + return [ + 'videoId', + 'trackerId', + 'createdAt', + 'updatedAt' + ] + } + + getRedundancyAttributes () { + return [ 'id', 'fileUrl' ] + } + + getActorAttributes () { + let attributeKeys = [ + 'id', + 'preferredUsername', + 'url', + 'serverId', + 'avatarId' + ] + + if (this.mode === 'get') { + attributeKeys = attributeKeys.concat([ + 'type', + 'followersCount', + 'followingCount', + 'inboxUrl', + 'outboxUrl', + 'sharedInboxUrl', + 'followersUrl', + 'followingUrl', + 'remoteCreatedAt', + 'createdAt', + 'updatedAt' + ]) + } + + return attributeKeys + } + + getAvatarAttributes () { + let attributeKeys = [ + 'id', + 'filename', + 'fileUrl', + 'onDisk', + 'createdAt', + 'updatedAt' + ] + + if (this.mode === 'get') { + attributeKeys = attributeKeys.concat([ + 'height', + 'width', + 'type' + ]) + } + + return attributeKeys + } + + getServerAttributes () { + return [ 'id', 'host' ] + } + + getVideoAttributes () { + return [ + 'id', + 'uuid', + 'name', + 'category', + 'licence', + 'language', + 'privacy', + 'nsfw', + 'description', + 'support', + 'duration', + 'views', + 'likes', + 'dislikes', + 'remote', + 'isLive', + 'url', + 'commentsEnabled', + 'downloadEnabled', + 'waitTranscoding', + 'state', + 'publishedAt', + 'originallyPublishedAt', + 'channelId', + 'createdAt', + 'updatedAt' + ] + } +} diff --git a/server/models/video/sql/shared/video-model-builder.ts b/server/models/video/sql/shared/video-model-builder.ts new file mode 100644 index 000000000..9719f6d2e --- /dev/null +++ b/server/models/video/sql/shared/video-model-builder.ts @@ -0,0 +1,268 @@ +import { pick } from 'lodash' +import { AccountModel } from '@server/models/account/account' +import { ActorModel } from '@server/models/actor/actor' +import { ActorImageModel } from '@server/models/actor/actor-image' +import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy' +import { ServerModel } from '@server/models/server/server' +import { TrackerModel } from '@server/models/server/tracker' +import { UserVideoHistoryModel } from '@server/models/user/user-video-history' +import { ScheduleVideoUpdateModel } from '../../schedule-video-update' +import { TagModel } from '../../tag' +import { ThumbnailModel } from '../../thumbnail' +import { VideoModel } from '../../video' +import { VideoBlacklistModel } from '../../video-blacklist' +import { VideoChannelModel } from '../../video-channel' +import { VideoFileModel } from '../../video-file' +import { VideoLiveModel } from '../../video-live' +import { VideoStreamingPlaylistModel } from '../../video-streaming-playlist' +import { VideoAttributes } from './video-attributes' + +export class VideoModelBuilder { + private videosMemo: { [ id: number ]: VideoModel } + private videoStreamingPlaylistMemo: { [ id: number ]: VideoStreamingPlaylistModel } + private videoFileMemo: { [ id: number ]: VideoFileModel } + + private thumbnailsDone: Set + private historyDone: Set + private blacklistDone: Set + private liveDone: Set + private redundancyDone: Set + private scheduleVideoUpdateDone: Set + + private trackersDone: Set + private tagsDone: Set + + private videos: VideoModel[] + + private readonly buildOpts = { raw: true, isNewRecord: false } + + constructor ( + readonly mode: 'get' | 'list', + readonly videoAttributes: VideoAttributes + ) { + + } + + buildVideosFromRows (rows: any[]) { + this.reinit() + + for (const row of rows) { + this.buildVideo(row) + + const videoModel = this.videosMemo[row.id] + + this.setUserHistory(row, videoModel) + this.addThumbnail(row, videoModel) + this.addWebTorrentFile(row, videoModel) + + this.addStreamingPlaylist(row, videoModel) + this.addStreamingPlaylistFile(row) + + if (this.mode === 'get') { + this.addTag(row, videoModel) + this.addTracker(row, videoModel) + this.setBlacklisted(row, videoModel) + this.setScheduleVideoUpdate(row, videoModel) + this.setLive(row, videoModel) + + if (row.VideoFiles.id) { + this.addRedundancy(row.VideoFiles.RedundancyVideos, this.videoFileMemo[row.VideoFiles.id]) + } + + if (row.VideoStreamingPlaylists.id) { + this.addRedundancy(row.VideoStreamingPlaylists.RedundancyVideos, this.videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) + } + } + } + + return this.videos + } + + private reinit () { + this.videosMemo = {} + this.videoStreamingPlaylistMemo = {} + this.videoFileMemo = {} + + this.thumbnailsDone = new Set() + this.historyDone = new Set() + this.blacklistDone = new Set() + this.liveDone = new Set() + this.redundancyDone = new Set() + this.scheduleVideoUpdateDone = new Set() + + this.trackersDone = new Set() + this.tagsDone = new Set() + + this.videos = [] + } + + private buildVideo (row: any) { + if (this.videosMemo[row.id]) return + + // Build Channel + const channel = row.VideoChannel + const channelModel = new VideoChannelModel(pick(channel, this.videoAttributes.getChannelAttributes()), this.buildOpts) + channelModel.Actor = this.buildActor(channel.Actor) + + const account = row.VideoChannel.Account + const accountModel = new AccountModel(pick(account, this.videoAttributes.getAccountAttributes()), this.buildOpts) + accountModel.Actor = this.buildActor(account.Actor) + + channelModel.Account = accountModel + + const videoModel = new VideoModel(pick(row, this.videoAttributes.getVideoAttributes()), this.buildOpts) + videoModel.VideoChannel = channelModel + + this.videosMemo[row.id] = videoModel + + videoModel.UserVideoHistories = [] + videoModel.Thumbnails = [] + videoModel.VideoFiles = [] + videoModel.VideoStreamingPlaylists = [] + videoModel.Tags = [] + videoModel.Trackers = [] + + // Keep rows order + this.videos.push(videoModel) + } + + private buildActor (rowActor: any) { + const avatarModel = rowActor.Avatar.id !== null + ? new ActorImageModel(pick(rowActor.Avatar, this.videoAttributes.getAvatarAttributes()), this.buildOpts) + : null + + const serverModel = rowActor.Server.id !== null + ? new ServerModel(pick(rowActor.Server, this.videoAttributes.getServerAttributes()), this.buildOpts) + : null + + const actorModel = new ActorModel(pick(rowActor, this.videoAttributes.getActorAttributes()), this.buildOpts) + actorModel.Avatar = avatarModel + actorModel.Server = serverModel + + return actorModel + } + + private setUserHistory (row: any, videoModel: VideoModel) { + if (!row.userVideoHistory?.id || this.historyDone.has(row.userVideoHistory.id)) return + + const attributes = pick(row.userVideoHistory, this.videoAttributes.getUserHistoryAttributes()) + const historyModel = new UserVideoHistoryModel(attributes, this.buildOpts) + videoModel.UserVideoHistories.push(historyModel) + + this.historyDone.add(row.userVideoHistory.id) + } + + private addThumbnail (row: any, videoModel: VideoModel) { + if (!row.Thumbnails?.id || this.thumbnailsDone.has(row.Thumbnails.id)) return + + const attributes = pick(row.Thumbnails, this.videoAttributes.getThumbnailAttributes()) + const thumbnailModel = new ThumbnailModel(attributes, this.buildOpts) + videoModel.Thumbnails.push(thumbnailModel) + + this.thumbnailsDone.add(row.Thumbnails.id) + } + + private addWebTorrentFile (row: any, videoModel: VideoModel) { + if (!row.VideoFiles?.id || this.videoFileMemo[row.VideoFiles.id]) return + + const attributes = pick(row.VideoFiles, this.videoAttributes.getFileAttributes()) + const videoFileModel = new VideoFileModel(attributes, this.buildOpts) + videoModel.VideoFiles.push(videoFileModel) + + this.videoFileMemo[row.VideoFiles.id] = videoFileModel + } + + private addStreamingPlaylist (row: any, videoModel: VideoModel) { + if (!row.VideoStreamingPlaylists?.id || this.videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) return + + const attributes = pick(row.VideoStreamingPlaylists, this.videoAttributes.getStreamingPlaylistAttributes()) + const streamingPlaylist = new VideoStreamingPlaylistModel(attributes, this.buildOpts) + streamingPlaylist.VideoFiles = [] + + videoModel.VideoStreamingPlaylists.push(streamingPlaylist) + + this.videoStreamingPlaylistMemo[streamingPlaylist.id] = streamingPlaylist + } + + private addStreamingPlaylistFile (row: any) { + if (!row.VideoStreamingPlaylists?.VideoFiles?.id || this.videoFileMemo[row.VideoStreamingPlaylists.VideoFiles.id]) return + + const streamingPlaylist = this.videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id] + + const attributes = pick(row.VideoStreamingPlaylists.VideoFiles, this.videoAttributes.getFileAttributes()) + const videoFileModel = new VideoFileModel(attributes, this.buildOpts) + streamingPlaylist.VideoFiles.push(videoFileModel) + + this.videoFileMemo[row.VideoStreamingPlaylists.VideoFiles.id] = videoFileModel + } + + private addRedundancy (redundancyRow: any, to: VideoFileModel | VideoStreamingPlaylistModel) { + if (!to.RedundancyVideos) to.RedundancyVideos = [] + + if (!redundancyRow?.id || this.redundancyDone.has(redundancyRow.id)) return + + const attributes = pick(redundancyRow, this.videoAttributes.getRedundancyAttributes()) + const redundancyModel = new VideoRedundancyModel(attributes, this.buildOpts) + to.RedundancyVideos.push(redundancyModel) + + this.redundancyDone.add(redundancyRow.id) + } + + private addTag (row: any, videoModel: VideoModel) { + if (!row.Tags?.name) return + const association = row.Tags.VideoTagModel + + const key = `${association.videoId}-${association.tagId}` + if (this.tagsDone.has(key)) return + + const attributes = pick(row.Tags, this.videoAttributes.getTagAttributes()) + const tagModel = new TagModel(attributes, this.buildOpts) + videoModel.Tags.push(tagModel) + + this.tagsDone.add(key) + } + + private addTracker (row: any, videoModel: VideoModel) { + if (!row.Trackers?.id) return + const association = row.Trackers.VideoTrackerModel + + const key = `${association.videoId}-${association.trackerId}` + if (this.trackersDone.has(key)) return + + const attributes = pick(row.Trackers, this.videoAttributes.getTrackerAttributes()) + const trackerModel = new TrackerModel(attributes, this.buildOpts) + videoModel.Trackers.push(trackerModel) + + this.trackersDone.add(key) + } + + private setBlacklisted (row: any, videoModel: VideoModel) { + if (!row.VideoBlacklist?.id) return + if (this.blacklistDone.has(row.VideoBlacklist.id)) return + + const attributes = pick(row.VideoBlacklist, this.videoAttributes.getBlacklistedAttributes()) + videoModel.VideoBlacklist = new VideoBlacklistModel(attributes, this.buildOpts) + + this.blacklistDone.add(row.VideoBlacklist.id) + } + + private setScheduleVideoUpdate (row: any, videoModel: VideoModel) { + if (!row.ScheduleVideoUpdate?.id) return + if (this.scheduleVideoUpdateDone.has(row.ScheduleVideoUpdate.id)) return + + const attributes = pick(row.ScheduleVideoUpdate, this.videoAttributes.getScheduleUpdateAttributes()) + videoModel.ScheduleVideoUpdate = new ScheduleVideoUpdateModel(attributes, this.buildOpts) + + this.scheduleVideoUpdateDone.add(row.ScheduleVideoUpdate.id) + } + + private setLive (row: any, videoModel: VideoModel) { + if (!row.VideoLive?.id) return + if (this.liveDone.has(row.VideoLive.id)) return + + const attributes = pick(row.VideoLive, this.videoAttributes.getLiveAttributes()) + videoModel.VideoLive = new VideoLiveModel(attributes, this.buildOpts) + + this.liveDone.add(row.ScheduleVideoUpdate.id) + } +} -- cgit v1.2.3