1
0
Fork 0

Cleanup video model scopes

This commit is contained in:
Chocobozzz 2021-06-11 14:45:58 +02:00
parent 7c3a6636fd
commit 69322042c4
No known key found for this signature in database
GPG key ID: 583A612D890159BE

View file

@ -56,19 +56,7 @@ import {
import { getVideoFileResolution } from '../../helpers/ffprobe-utils' import { getVideoFileResolution } from '../../helpers/ffprobe-utils'
import { logger } from '../../helpers/logger' import { logger } from '../../helpers/logger'
import { CONFIG } from '../../initializers/config' import { CONFIG } from '../../initializers/config'
import { import { ACTIVITY_PUB, API_VERSION, CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, STATIC_PATHS, WEBSERVER } from '../../initializers/constants'
ACTIVITY_PUB,
API_VERSION,
CONSTRAINTS_FIELDS,
LAZY_STATIC_PATHS,
STATIC_PATHS,
VIDEO_CATEGORIES,
VIDEO_LANGUAGES,
VIDEO_LICENCES,
VIDEO_PRIVACIES,
VIDEO_STATES,
WEBSERVER
} from '../../initializers/constants'
import { sendDeleteVideo } from '../../lib/activitypub/send' import { sendDeleteVideo } from '../../lib/activitypub/send'
import { import {
MChannel, MChannel,
@ -136,20 +124,16 @@ import { VideoTagModel } from './video-tag'
import { VideoViewModel } from './video-view' import { VideoViewModel } from './video-view'
export enum ScopeNames { export enum ScopeNames {
AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
FOR_API = 'FOR_API', FOR_API = 'FOR_API',
WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS',
WITH_TAGS = 'WITH_TAGS', WITH_TAGS = 'WITH_TAGS',
WITH_TRACKERS = 'WITH_TRACKERS',
WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES', WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES',
WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE',
WITH_BLACKLISTED = 'WITH_BLACKLISTED', WITH_BLACKLISTED = 'WITH_BLACKLISTED',
WITH_USER_HISTORY = 'WITH_USER_HISTORY',
WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS',
WITH_USER_ID = 'WITH_USER_ID',
WITH_IMMUTABLE_ATTRIBUTES = 'WITH_IMMUTABLE_ATTRIBUTES', WITH_IMMUTABLE_ATTRIBUTES = 'WITH_IMMUTABLE_ATTRIBUTES',
WITH_THUMBNAILS = 'WITH_THUMBNAILS', WITH_USER_HISTORY = 'WITH_USER_HISTORY',
WITH_LIVE = 'WITH_LIVE' WITH_THUMBNAILS = 'WITH_THUMBNAILS'
} }
export type ForAPIOptions = { export type ForAPIOptions = {
@ -245,30 +229,6 @@ export type AvailableForListIDsOptions = {
} }
] ]
}, },
[ScopeNames.WITH_LIVE]: {
include: [
{
model: VideoLiveModel.unscoped(),
required: false
}
]
},
[ScopeNames.WITH_USER_ID]: {
include: [
{
attributes: [ 'accountId' ],
model: VideoChannelModel.unscoped(),
required: true,
include: [
{
attributes: [ 'userId' ],
model: AccountModel.unscoped(),
required: true
}
]
}
]
},
[ScopeNames.WITH_ACCOUNT_DETAILS]: { [ScopeNames.WITH_ACCOUNT_DETAILS]: {
include: [ include: [
{ {
@ -326,14 +286,6 @@ export type AvailableForListIDsOptions = {
[ScopeNames.WITH_TAGS]: { [ScopeNames.WITH_TAGS]: {
include: [ TagModel ] include: [ TagModel ]
}, },
[ScopeNames.WITH_TRACKERS]: {
include: [
{
attributes: [ 'id', 'url' ],
model: TrackerModel
}
]
},
[ScopeNames.WITH_BLACKLISTED]: { [ScopeNames.WITH_BLACKLISTED]: {
include: [ include: [
{ {
@ -1439,7 +1391,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
const rawQuery = `UPDATE "video" SET "${field}" = ` + const rawQuery = `UPDATE "video" SET "${field}" = ` +
'(' + '(' +
'SELECT COUNT(id) FROM "accountVideoRate" WHERE "accountVideoRate"."videoId" = "video"."id" AND type = :rateType' + 'SELECT COUNT(id) FROM "accountVideoRate" WHERE "accountVideoRate"."videoId" = "video"."id" AND type = :rateType' +
') ' + ') ' +
'WHERE "video"."id" = :videoId' 'WHERE "video"."id" = :videoId'
@ -1467,15 +1419,15 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
.then(results => results.length === 1) .then(results => results.length === 1)
} }
static bulkUpdateSupportField (videoChannel: MChannel, t: Transaction) { static bulkUpdateSupportField (ofChannel: MChannel, t: Transaction) {
const options = { const options = {
where: { where: {
channelId: videoChannel.id channelId: ofChannel.id
}, },
transaction: t transaction: t
} }
return VideoModel.update({ support: videoChannel.support }, options) return VideoModel.update({ support: ofChannel.support }, options)
} }
static getAllIdsFromChannel (videoChannel: MChannelId): Promise<number[]> { static getAllIdsFromChannel (videoChannel: MChannelId): Promise<number[]> {