Fix languageOneOf filter with only _unknown

This commit is contained in:
Chocobozzz 2020-04-16 17:00:40 +02:00
parent 2c0ccd4b3f
commit 14cbb9a65a
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 18 additions and 13 deletions

View File

@ -203,25 +203,30 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
} }
if (options.languageOneOf) { 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')) { languagesQueryParts.push(
languagesQuery += '"video"."language" IS NULL OR '
}
and.push(
languagesQuery +
' EXISTS (' + ' EXISTS (' +
' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' + ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' +
' IN (' + createSafeIn(model, options.languageOneOf) + ') AND ' + ' IN (' + createSafeIn(model, languages) + ') AND ' +
' "videoCaption"."videoId" = "video"."id"' + ' "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 // We don't exclude results in this if so if we do a count we don't need to add this complex clauses
if (options.trendingDays && options.isCount !== true) { if (options.trendingDays && options.isCount !== true) {
const viewsGteDate = new Date(new Date().getTime() - (24 * 3600 * 1000) * options.trendingDays) const viewsGteDate = new Date(new Date().getTime() - (24 * 3600 * 1000) * options.trendingDays)