X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=20e1f1c4aa97c043243001a231b75d23df473f17;hb=0374b6b5cd685316f924874b2a3068bb345eb0dd;hp=eacffe1864156d84d84e0cc2ee817c892cd354ae;hpb=2f1756a03ccf3546f9bbcd98bc149e350d3d950a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index eacffe186..20e1f1c4a 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1,18 +1,7 @@ import * as Bluebird from 'bluebird' import { maxBy, minBy } from 'lodash' import { join } from 'path' -import { - CountOptions, - FindOptions, - IncludeOptions, - ModelIndexesOptions, - Op, - QueryTypes, - ScopeOptions, - Sequelize, - Transaction, - WhereOptions -} from 'sequelize' +import { CountOptions, FindOptions, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' import { AllowNull, BeforeDestroy, @@ -136,8 +125,7 @@ import { MVideoThumbnailBlacklist, MVideoWithAllFiles, MVideoWithFile, - MVideoWithRights, - MStreamingPlaylistFiles + MVideoWithRights } from '../../typings/models' import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file' import { MThumbnail } from '../../typings/models/video/thumbnail' @@ -145,74 +133,6 @@ import { VideoFile } from '@shared/models/videos/video-file.model' import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' import validator from 'validator' -// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation -const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ - buildTrigramSearchIndex('video_name_trigram', 'name'), - - { fields: [ 'createdAt' ] }, - { - fields: [ - { name: 'publishedAt', order: 'DESC' }, - { name: 'id', order: 'ASC' } - ] - }, - { fields: [ 'duration' ] }, - { fields: [ 'views' ] }, - { fields: [ 'channelId' ] }, - { - fields: [ 'originallyPublishedAt' ], - where: { - originallyPublishedAt: { - [Op.ne]: null - } - } - }, - { - fields: [ 'category' ], // We don't care videos with an unknown category - where: { - category: { - [Op.ne]: null - } - } - }, - { - fields: [ 'licence' ], // We don't care videos with an unknown licence - where: { - licence: { - [Op.ne]: null - } - } - }, - { - fields: [ 'language' ], // We don't care videos with an unknown language - where: { - language: { - [Op.ne]: null - } - } - }, - { - fields: [ 'nsfw' ], // Most of the videos are not NSFW - where: { - nsfw: true - } - }, - { - fields: [ 'remote' ], // Only index local videos - where: { - remote: false - } - }, - { - fields: [ 'uuid' ], - unique: true - }, - { - fields: [ 'url' ], - unique: true - } -] - export enum ScopeNames { AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', FOR_API = 'FOR_API', @@ -292,7 +212,7 @@ export type AvailableForListIDsOptions = { if (options.ids) { query.where = { id: { - [ Op.in ]: options.ids // FIXME: sequelize ANY seems broken + [ Op.in ]: options.ids } } } @@ -760,7 +680,72 @@ export type AvailableForListIDsOptions = { })) @Table({ tableName: 'video', - indexes + indexes: [ + buildTrigramSearchIndex('video_name_trigram', 'name'), + + { fields: [ 'createdAt' ] }, + { + fields: [ + { name: 'publishedAt', order: 'DESC' }, + { name: 'id', order: 'ASC' } + ] + }, + { fields: [ 'duration' ] }, + { fields: [ 'views' ] }, + { fields: [ 'channelId' ] }, + { + fields: [ 'originallyPublishedAt' ], + where: { + originallyPublishedAt: { + [Op.ne]: null + } + } + }, + { + fields: [ 'category' ], // We don't care videos with an unknown category + where: { + category: { + [Op.ne]: null + } + } + }, + { + fields: [ 'licence' ], // We don't care videos with an unknown licence + where: { + licence: { + [Op.ne]: null + } + } + }, + { + fields: [ 'language' ], // We don't care videos with an unknown language + where: { + language: { + [Op.ne]: null + } + } + }, + { + fields: [ 'nsfw' ], // Most of the videos are not NSFW + where: { + nsfw: true + } + }, + { + fields: [ 'remote' ], // Only index local videos + where: { + remote: false + } + }, + { + fields: [ 'uuid' ], + unique: true + }, + { + fields: [ 'url' ], + unique: true + } + ] }) export class VideoModel extends Model {