aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-16 17:00:40 +0200
committerChocobozzz <me@florianbigard.com>2020-04-16 17:00:40 +0200
commit14cbb9a65a1b2853c93df429fcc3df9004a5c940 (patch)
tree4b8d780633cdd42158f5e9571e51738eb4b89afc /server/models
parent2c0ccd4b3f5ec5633879e6b42cd5175e4de207cc (diff)
downloadPeerTube-14cbb9a65a1b2853c93df429fcc3df9004a5c940.tar.gz
PeerTube-14cbb9a65a1b2853c93df429fcc3df9004a5c940.tar.zst
PeerTube-14cbb9a65a1b2853c93df429fcc3df9004a5c940.zip
Fix languageOneOf filter with only _unknown
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video-query-builder.ts31
1 files 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)
203 } 203 }
204 204
205 if (options.languageOneOf) { 205 if (options.languageOneOf) {
206 replacements.languageOneOf = options.languageOneOf.filter(l => l && l !== '_unknown') 206 const languages = options.languageOneOf.filter(l => l && l !== '_unknown')
207 207 const languagesQueryParts: string[] = []
208 let languagesQuery = '("video"."language" IN (:languageOneOf) OR ' 208
209 if (languages.length !== 0) {
210 languagesQueryParts.push('("video"."language" IN (:languageOneOf)')
211 replacements.languageOneOf = languages
212
213 languagesQueryParts.push(
214 ' EXISTS (' +
215 ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' +
216 ' IN (' + createSafeIn(model, languages) + ') AND ' +
217 ' "videoCaption"."videoId" = "video"."id"' +
218 ' )' +
219 ')'
220 )
221 }
209 222
210 if (options.languageOneOf.includes('_unknown')) { 223 if (options.languageOneOf.includes('_unknown')) {
211 languagesQuery += '"video"."language" IS NULL OR ' 224 languagesQueryParts.push('"video"."language" IS NULL')
212 } 225 }
213 226
214 and.push( 227 and.push(languagesQueryParts.join(' OR '))
215 languagesQuery +
216 ' EXISTS (' +
217 ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' +
218 ' IN (' + createSafeIn(model, options.languageOneOf) + ') AND ' +
219 ' "videoCaption"."videoId" = "video"."id"' +
220 ' )' +
221 ')'
222 )
223 } 228 }
224 229
225 // We don't exclude results in this if so if we do a count we don't need to add this complex clauses 230 // We don't exclude results in this if so if we do a count we don't need to add this complex clauses