From 6b0c3c7ca917ad09a011c2821f5bd1a2485aebca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 9 Jan 2020 09:26:59 +0100 Subject: Optimize list my playlists SQL query --- server/models/video/video-playlist.ts | 40 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'server/models/video/video-playlist.ts') diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 71a580249..bcdda36e5 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -68,7 +68,7 @@ type AvailableForListOptions = { type?: VideoPlaylistType accountId?: number videoChannelId?: number - privateAndUnlisted?: boolean, + listMyPlaylists?: boolean, search?: string } @@ -124,27 +124,31 @@ type AvailableForListOptions = { ] }, [ ScopeNames.AVAILABLE_FOR_LIST ]: (options: AvailableForListOptions) => { - // Only list local playlists OR playlists that are on an instance followed by actorId - const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) - const whereActor = { - [ Op.or ]: [ - { - serverId: null - }, - { - serverId: { - [ Op.in ]: literal(inQueryInstanceFollow) - } - } - ] - } + + let whereActor: WhereOptions = {} const whereAnd: WhereOptions[] = [] - if (options.privateAndUnlisted !== true) { + if (options.listMyPlaylists !== true) { whereAnd.push({ privacy: VideoPlaylistPrivacy.PUBLIC }) + + // Only list local playlists OR playlists that are on an instance followed by actorId + const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) + + whereActor = { + [ Op.or ]: [ + { + serverId: null + }, + { + serverId: { + [ Op.in ]: literal(inQueryInstanceFollow) + } + } + ] + } } if (options.accountId) { @@ -301,7 +305,7 @@ export class VideoPlaylistModel extends Model { type?: VideoPlaylistType, accountId?: number, videoChannelId?: number, - privateAndUnlisted?: boolean, + listMyPlaylists?: boolean, search?: string }) { const query = { @@ -319,7 +323,7 @@ export class VideoPlaylistModel extends Model { followerActorId: options.followerActorId, accountId: options.accountId, videoChannelId: options.videoChannelId, - privateAndUnlisted: options.privateAndUnlisted, + listMyPlaylists: options.listMyPlaylists, search: options.search } as AvailableForListOptions ] -- cgit v1.2.3