From 8f31261f77c6e521917b3f629b223ccc8df50960 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 20 Apr 2020 10:24:58 +0200 Subject: Fix videos languages filter SQL query --- server/models/video/video-query-builder.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts index 015bf43de..8f0a814de 100644 --- a/server/models/video/video-query-builder.ts +++ b/server/models/video/video-query-builder.ts @@ -207,15 +207,14 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) const languagesQueryParts: string[] = [] if (languages.length !== 0) { - languagesQueryParts.push('("video"."language" IN (:languageOneOf)') + languagesQueryParts.push('"video"."language" IN (:languageOneOf)') replacements.languageOneOf = languages languagesQueryParts.push( - ' EXISTS (' + - ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' + - ' IN (' + createSafeIn(model, languages) + ') AND ' + - ' "videoCaption"."videoId" = "video"."id"' + - ' )' + + 'EXISTS (' + + ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' + + ' IN (' + createSafeIn(model, languages) + ') AND ' + + ' "videoCaption"."videoId" = "video"."id"' + ')' ) } @@ -224,7 +223,9 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) languagesQueryParts.push('"video"."language" IS NULL') } - and.push(languagesQueryParts.join(' OR ')) + if (languagesQueryParts.length !== 0) { + and.push('(' + languagesQueryParts.join(' OR ') + ')') + } } // We don't exclude results in this if so if we do a count we don't need to add this complex clauses -- cgit v1.2.3