Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Optimize videos sql query

Chocobozzzd4f328e5748c
diff --git a/server/core/models/video/sql/video/videos-id-list-query-builder.ts b/server/core/models/video/sql/video/videos-id-list-query-builder.ts
index 6fa576ce09..a2b2328b40 100644
--- a/server/core/models/video/sql/video/videos-id-list-query-builder.ts
+++ b/server/core/models/video/sql/video/videos-id-list-query-builder.ts
@@ -466,13 +466,17 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery {
' INNER JOIN "actorFollow" "actorFollowShare" ON "actorFollowShare"."targetActorId" = "videoShare"."actorId" ' +
' AND "actorFollowShare"."actorId" = :followerActorId AND "actorFollowShare"."state" = \'accepted\' ' +
' WHERE "videoShare"."videoId" = "video"."id"' +
- ' )' +
- ' OR' +
- ' EXISTS (' + // Videos published by accounts we follow
- ' SELECT 1 from "actorFollow" ' +
- ' WHERE ("actorFollow"."targetActorId" = "accountActor"."id" OR "actorFollow"."targetActorId" = "channelActor"."id") ' +
+ ' UNION ALL ' +
+ ' SELECT 1 from "actorFollow" ' + // Videos published by accounts we follow
+ ' WHERE "actorFollow"."targetActorId" = "accountActor"."id" ' +
' AND "actorFollow"."actorId" = :followerActorId ' +
' AND "actorFollow"."state" = \'accepted\'' +
+ ' UNION ALL ' +
+ ' SELECT 1 from "actorFollow" ' + // Videos published by channels we follow
+ ' WHERE "actorFollow"."targetActorId" = "channelActor"."id" ' +
+ ' AND "actorFollow"."actorId" = :followerActorId ' +
+ ' AND "actorFollow"."state" = \'accepted\'' +
+ ' LIMIT 1' +
' )'
if (options.orLocalVideos) {