Fix videos languages filter SQL query

pull/2669/head
Chocobozzz 2020-04-20 10:24:58 +02:00
parent 6ed2e4eaf3
commit 8f31261f77
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 8 additions and 7 deletions

View File

@ -207,15 +207,14 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
const languagesQueryParts: string[] = [] const languagesQueryParts: string[] = []
if (languages.length !== 0) { if (languages.length !== 0) {
languagesQueryParts.push('("video"."language" IN (:languageOneOf)') languagesQueryParts.push('"video"."language" IN (:languageOneOf)')
replacements.languageOneOf = languages replacements.languageOneOf = languages
languagesQueryParts.push( languagesQueryParts.push(
' EXISTS (' + 'EXISTS (' +
' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' + ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' +
' IN (' + createSafeIn(model, languages) + ') AND ' + ' IN (' + createSafeIn(model, languages) + ') AND ' +
' "videoCaption"."videoId" = "video"."id"' + ' "videoCaption"."videoId" = "video"."id"' +
' )' +
')' ')'
) )
} }
@ -224,7 +223,9 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
languagesQueryParts.push('"video"."language" IS NULL') 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 // We don't exclude results in this if so if we do a count we don't need to add this complex clauses