diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-18 19:37:35 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-18 19:37:35 +0100 |
commit | 2d9ab59061057ae9686b65b61e9d59e47f03fae9 (patch) | |
tree | 432d331441102e54180b567e6e7815acf2878528 | |
parent | 2e866cc75de7f34aeca4575d8dea1af597131563 (diff) | |
download | PeerTube-2d9ab59061057ae9686b65b61e9d59e47f03fae9.tar.gz PeerTube-2d9ab59061057ae9686b65b61e9d59e47f03fae9.tar.zst PeerTube-2d9ab59061057ae9686b65b61e9d59e47f03fae9.zip |
Fix videos list sql request
Sequelize my love <3
-rw-r--r-- | server/models/video/video.ts | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 71e37e147..d22d57310 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -31,7 +31,6 @@ import { sendDeleteVideo } from '../../lib/activitypub/send' | |||
31 | import { AccountModel } from '../account/account' | 31 | import { AccountModel } from '../account/account' |
32 | import { AccountVideoRateModel } from '../account/account-video-rate' | 32 | import { AccountVideoRateModel } from '../account/account-video-rate' |
33 | import { ActorModel } from '../activitypub/actor' | 33 | import { ActorModel } from '../activitypub/actor' |
34 | import { ActorFollowModel } from '../activitypub/actor-follow' | ||
35 | import { ServerModel } from '../server/server' | 34 | import { ServerModel } from '../server/server' |
36 | import { getSort, throwIfNotValid } from '../utils' | 35 | import { getSort, throwIfNotValid } from '../utils' |
37 | import { TagModel } from './tag' | 36 | import { TagModel } from './tag' |
@@ -54,33 +53,27 @@ enum ScopeNames { | |||
54 | 53 | ||
55 | @Scopes({ | 54 | @Scopes({ |
56 | [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number) => ({ | 55 | [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number) => ({ |
57 | subQuery: false, | ||
58 | where: { | 56 | where: { |
59 | id: { | 57 | id: { |
60 | [Sequelize.Op.notIn]: Sequelize.literal( | 58 | [Sequelize.Op.notIn]: Sequelize.literal( |
61 | '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")' | 59 | '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")' |
60 | ), | ||
61 | [ Sequelize.Op.in ]: Sequelize.literal( | ||
62 | '(' + | ||
63 | 'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' + | ||
64 | 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' + | ||
65 | 'WHERE "actorFollow"."actorId" = ' + parseInt(actorId.toString(), 10) + | ||
66 | ' UNION ' + | ||
67 | 'SELECT "video"."id" AS "id" FROM "video" ' + | ||
68 | 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' + | ||
69 | 'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' + | ||
70 | 'INNER JOIN "actor" ON "account"."actorId" = "actor"."id" ' + | ||
71 | 'LEFT JOIN "actorFollow" ON "actorFollow"."targetActorId" = "actor"."id" ' + | ||
72 | 'WHERE "actor"."serverId" IS NULL OR "actorFollow"."actorId" = ' + parseInt(actorId.toString(), 10) + | ||
73 | ')' | ||
62 | ) | 74 | ) |
63 | }, | 75 | }, |
64 | privacy: VideoPrivacy.PUBLIC, | 76 | privacy: VideoPrivacy.PUBLIC |
65 | [Sequelize.Op.or]: [ | ||
66 | { | ||
67 | '$VideoChannel.Account.Actor.serverId$': null | ||
68 | }, | ||
69 | { | ||
70 | '$VideoChannel.Account.Actor.ActorFollowers.actorId$': actorId | ||
71 | }, | ||
72 | { | ||
73 | id: { | ||
74 | [ Sequelize.Op.in ]: Sequelize.literal( | ||
75 | '(' + | ||
76 | 'SELECT "videoShare"."videoId" FROM "videoShare" ' + | ||
77 | 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' + | ||
78 | 'WHERE "actorFollow"."actorId" = ' + parseInt(actorId.toString(), 10) + | ||
79 | ')' | ||
80 | ) | ||
81 | } | ||
82 | } | ||
83 | ] | ||
84 | }, | 77 | }, |
85 | include: [ | 78 | include: [ |
86 | { | 79 | { |
@@ -100,14 +93,7 @@ enum ScopeNames { | |||
100 | include: [ | 93 | include: [ |
101 | { | 94 | { |
102 | attributes: [ 'host' ], | 95 | attributes: [ 'host' ], |
103 | model: ServerModel.unscoped(), | 96 | model: ServerModel.unscoped() |
104 | required: false | ||
105 | }, | ||
106 | { | ||
107 | attributes: [ ], | ||
108 | model: ActorFollowModel.unscoped(), | ||
109 | as: 'ActorFollowers', | ||
110 | required: false | ||
111 | } | 97 | } |
112 | ] | 98 | ] |
113 | } | 99 | } |