From 14cbb9a65a1b2853c93df429fcc3df9004a5c940 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Apr 2020 17:00:40 +0200 Subject: [PATCH] Fix languageOneOf filter with only _unknown --- server/models/video/video-query-builder.ts | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) 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') + const languages = options.languageOneOf.filter(l => l && l !== '_unknown') + const languagesQueryParts: string[] = [] - let languagesQuery = '("video"."language" IN (:languageOneOf) OR ' + if (languages.length !== 0) { + languagesQueryParts.push('("video"."language" IN (:languageOneOf)') + replacements.languageOneOf = languages - if (options.languageOneOf.includes('_unknown')) { - languagesQuery += '"video"."language" IS NULL OR ' + languagesQueryParts.push( + ' EXISTS (' + + ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' + + ' IN (' + createSafeIn(model, languages) + ') AND ' + + ' "videoCaption"."videoId" = "video"."id"' + + ' )' + + ')' + ) } - and.push( - languagesQuery + - ' EXISTS (' + - ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' + - ' IN (' + createSafeIn(model, options.languageOneOf) + ') AND ' + - ' "videoCaption"."videoId" = "video"."id"' + - ' )' + - ')' - ) + if (options.languageOneOf.includes('_unknown')) { + languagesQueryParts.push('"video"."language" IS NULL') + } + + 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