From: Chocobozzz Date: Mon, 20 Apr 2020 08:24:58 +0000 (+0200) Subject: Fix videos languages filter SQL query X-Git-Tag: v2.2.0-rc.1~176 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8f31261f77c6e521917b3f629b223ccc8df50960;p=oweals%2Fpeertube.git Fix videos languages filter SQL query --- 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