aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-09 09:26:59 +0100
committerChocobozzz <me@florianbigard.com>2020-01-09 09:27:21 +0100
commit6b0c3c7ca917ad09a011c2821f5bd1a2485aebca (patch)
treea660791ddc78c95fe69469bd7c33e0e719fba871 /server/models/video
parent119b16e5acffff1901f23c7a0188c78272453e7d (diff)
downloadPeerTube-6b0c3c7ca917ad09a011c2821f5bd1a2485aebca.tar.gz
PeerTube-6b0c3c7ca917ad09a011c2821f5bd1a2485aebca.tar.zst
PeerTube-6b0c3c7ca917ad09a011c2821f5bd1a2485aebca.zip
Optimize list my playlists SQL query
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-playlist.ts40
1 files changed, 22 insertions, 18 deletions
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 = {
68 type?: VideoPlaylistType 68 type?: VideoPlaylistType
69 accountId?: number 69 accountId?: number
70 videoChannelId?: number 70 videoChannelId?: number
71 privateAndUnlisted?: boolean, 71 listMyPlaylists?: boolean,
72 search?: string 72 search?: string
73} 73}
74 74
@@ -124,27 +124,31 @@ type AvailableForListOptions = {
124 ] 124 ]
125 }, 125 },
126 [ ScopeNames.AVAILABLE_FOR_LIST ]: (options: AvailableForListOptions) => { 126 [ ScopeNames.AVAILABLE_FOR_LIST ]: (options: AvailableForListOptions) => {
127 // Only list local playlists OR playlists that are on an instance followed by actorId 127
128 const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) 128 let whereActor: WhereOptions = {}
129 const whereActor = {
130 [ Op.or ]: [
131 {
132 serverId: null
133 },
134 {
135 serverId: {
136 [ Op.in ]: literal(inQueryInstanceFollow)
137 }
138 }
139 ]
140 }
141 129
142 const whereAnd: WhereOptions[] = [] 130 const whereAnd: WhereOptions[] = []
143 131
144 if (options.privateAndUnlisted !== true) { 132 if (options.listMyPlaylists !== true) {
145 whereAnd.push({ 133 whereAnd.push({
146 privacy: VideoPlaylistPrivacy.PUBLIC 134 privacy: VideoPlaylistPrivacy.PUBLIC
147 }) 135 })
136
137 // Only list local playlists OR playlists that are on an instance followed by actorId
138 const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId)
139
140 whereActor = {
141 [ Op.or ]: [
142 {
143 serverId: null
144 },
145 {
146 serverId: {
147 [ Op.in ]: literal(inQueryInstanceFollow)
148 }
149 }
150 ]
151 }
148 } 152 }
149 153
150 if (options.accountId) { 154 if (options.accountId) {
@@ -301,7 +305,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
301 type?: VideoPlaylistType, 305 type?: VideoPlaylistType,
302 accountId?: number, 306 accountId?: number,
303 videoChannelId?: number, 307 videoChannelId?: number,
304 privateAndUnlisted?: boolean, 308 listMyPlaylists?: boolean,
305 search?: string 309 search?: string
306 }) { 310 }) {
307 const query = { 311 const query = {
@@ -319,7 +323,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
319 followerActorId: options.followerActorId, 323 followerActorId: options.followerActorId,
320 accountId: options.accountId, 324 accountId: options.accountId,
321 videoChannelId: options.videoChannelId, 325 videoChannelId: options.videoChannelId,
322 privateAndUnlisted: options.privateAndUnlisted, 326 listMyPlaylists: options.listMyPlaylists,
323 search: options.search 327 search: options.search
324 } as AvailableForListOptions 328 } as AvailableForListOptions
325 ] 329 ]