From: Chocobozzz Date: Thu, 16 Apr 2020 15:00:40 +0000 (+0200) Subject: Fix languageOneOf filter with only _unknown X-Git-Tag: v2.2.0-rc.1~184 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=14cbb9a65a1b2853c93df429fcc3df9004a5c940;p=oweals%2Fpeertube.git Fix languageOneOf filter with only _unknown --- diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts index 655abf198..015bf43de 100644 --- a/server/models/video/video-query-builder.ts +++ b/server/models/video/video-query-builder.ts @@ -203,23 +203,28 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) } if (options.languageOneOf) { - replacements.languageOneOf = options.languageOneOf.filter(l => l && l !== '_unknown') - - let languagesQuery = '("video"."language" IN (:languageOneOf) OR ' + const languages = options.languageOneOf.filter(l => l && l !== '_unknown') + const languagesQueryParts: string[] = [] + + if (languages.length !== 0) { + 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"' + + ' )' + + ')' + ) + } if (options.languageOneOf.includes('_unknown')) { - languagesQuery += '"video"."language" IS NULL OR ' + languagesQueryParts.push('"video"."language" IS NULL') } - and.push( - languagesQuery + - ' EXISTS (' + - ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' + - ' IN (' + createSafeIn(model, options.languageOneOf) + ') AND ' + - ' "videoCaption"."videoId" = "video"."id"' + - ' )' + - ')' - ) + 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