diff options
author | Chocobozzz <me@florianbigard.com> | 2019-12-23 11:24:54 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-12-23 13:44:23 +0100 |
commit | 0dfee3a3ac8fbf53236c74fd7eca37dbe97e3128 (patch) | |
tree | e2d14e9dcca2ddccff3a0a9c3c2137e8a771023a /server | |
parent | 1c5fed88c5a24d7870550167421af2c4174aaa21 (diff) | |
download | PeerTube-0dfee3a3ac8fbf53236c74fd7eca37dbe97e3128.tar.gz PeerTube-0dfee3a3ac8fbf53236c74fd7eca37dbe97e3128.tar.zst PeerTube-0dfee3a3ac8fbf53236c74fd7eca37dbe97e3128.zip |
Optimize local sql query
Diffstat (limited to 'server')
-rw-r--r-- | server/models/video/video.ts | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 316a66f35..913d2d4a9 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -143,7 +143,6 @@ import { MThumbnail } from '../../typings/models/video/thumbnail' | |||
143 | import { VideoFile } from '@shared/models/videos/video-file.model' | 143 | import { VideoFile } from '@shared/models/videos/video-file.model' |
144 | import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' | 144 | import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' |
145 | import * as validator from 'validator' | 145 | import * as validator from 'validator' |
146 | import { ActorFollowModel } from '@server/models/activitypub/actor-follow' | ||
147 | 146 | ||
148 | // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation | 147 | // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation |
149 | const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ | 148 | const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ |
@@ -216,7 +215,6 @@ export enum ScopeNames { | |||
216 | WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES', | 215 | WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES', |
217 | WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', | 216 | WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', |
218 | WITH_BLACKLISTED = 'WITH_BLACKLISTED', | 217 | WITH_BLACKLISTED = 'WITH_BLACKLISTED', |
219 | WITH_BLOCKLIST = 'WITH_BLOCKLIST', | ||
220 | WITH_USER_HISTORY = 'WITH_USER_HISTORY', | 218 | WITH_USER_HISTORY = 'WITH_USER_HISTORY', |
221 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', | 219 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', |
222 | WITH_USER_ID = 'WITH_USER_ID', | 220 | WITH_USER_ID = 'WITH_USER_ID', |
@@ -399,7 +397,13 @@ export type AvailableForListIDsOptions = { | |||
399 | query.subQuery = false | 397 | query.subQuery = false |
400 | } | 398 | } |
401 | 399 | ||
402 | if (options.filter || options.accountId || options.videoChannelId) { | 400 | if (options.filter && (options.filter === 'local' || options.filter === 'all-local')) { |
401 | whereAnd.push({ | ||
402 | remote: false | ||
403 | }) | ||
404 | } | ||
405 | |||
406 | if (options.accountId || options.videoChannelId) { | ||
403 | const videoChannelInclude: IncludeOptions = { | 407 | const videoChannelInclude: IncludeOptions = { |
404 | attributes: [], | 408 | attributes: [], |
405 | model: VideoChannelModel.unscoped(), | 409 | model: VideoChannelModel.unscoped(), |
@@ -412,28 +416,14 @@ export type AvailableForListIDsOptions = { | |||
412 | } | 416 | } |
413 | } | 417 | } |
414 | 418 | ||
415 | if (options.filter || options.accountId) { | 419 | if (options.accountId) { |
416 | const accountInclude: IncludeOptions = { | 420 | const accountInclude: IncludeOptions = { |
417 | attributes: [], | 421 | attributes: [], |
418 | model: AccountModel.unscoped(), | 422 | model: AccountModel.unscoped(), |
419 | required: true | 423 | required: true |
420 | } | 424 | } |
421 | 425 | ||
422 | if (options.filter) { | 426 | accountInclude.where = { id: options.accountId } |
423 | accountInclude.include = [ | ||
424 | { | ||
425 | attributes: [], | ||
426 | model: ActorModel.unscoped(), | ||
427 | required: true, | ||
428 | where: VideoModel.buildActorWhereWithFilter(options.filter) | ||
429 | } | ||
430 | ] | ||
431 | } | ||
432 | |||
433 | if (options.accountId) { | ||
434 | accountInclude.where = { id: options.accountId } | ||
435 | } | ||
436 | |||
437 | videoChannelInclude.include = [ accountInclude ] | 427 | videoChannelInclude.include = [ accountInclude ] |
438 | } | 428 | } |
439 | 429 | ||
@@ -593,9 +583,6 @@ export type AvailableForListIDsOptions = { | |||
593 | 583 | ||
594 | return query | 584 | return query |
595 | }, | 585 | }, |
596 | [ScopeNames.WITH_BLOCKLIST]: { | ||
597 | |||
598 | }, | ||
599 | [ ScopeNames.WITH_THUMBNAILS ]: { | 586 | [ ScopeNames.WITH_THUMBNAILS ]: { |
600 | include: [ | 587 | include: [ |
601 | { | 588 | { |
@@ -1713,16 +1700,6 @@ export class VideoModel extends Model<VideoModel> { | |||
1713 | } | 1700 | } |
1714 | } | 1701 | } |
1715 | 1702 | ||
1716 | private static buildActorWhereWithFilter (filter?: VideoFilter) { | ||
1717 | if (filter && (filter === 'local' || filter === 'all-local')) { | ||
1718 | return { | ||
1719 | serverId: null | ||
1720 | } | ||
1721 | } | ||
1722 | |||
1723 | return {} | ||
1724 | } | ||
1725 | |||
1726 | private static async getAvailableForApi ( | 1703 | private static async getAvailableForApi ( |
1727 | query: FindOptions & { where?: null }, // Forbid where field in query | 1704 | query: FindOptions & { where?: null }, // Forbid where field in query |
1728 | options: AvailableForListIDsOptions, | 1705 | options: AvailableForListIDsOptions, |