mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-22 16:56:39 -06:00
Try to optimize tagsOneOf/tagsAllOf SQL queries
Using a CTE because the query will probably return a few results I tried a IN clause but PG doesn't seem to be more efficient with it The CTE seems to be the only choice
This commit is contained in:
parent
a290fbf821
commit
d3dd952cc5
@ -434,28 +434,30 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery {
|
||||
private whereTagsOneOf (tagsOneOf: string[]) {
|
||||
const tagsOneOfLower = tagsOneOf.map(t => t.toLowerCase())
|
||||
|
||||
this.and.push(
|
||||
'EXISTS (' +
|
||||
' SELECT 1 FROM "videoTag" ' +
|
||||
this.cte.push(
|
||||
'"tagsOneOf" AS (' +
|
||||
' SELECT "videoTag"."videoId" AS "videoId" FROM "videoTag" ' +
|
||||
' INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
|
||||
' WHERE lower("tag"."name") IN (' + createSafeIn(this.sequelize, tagsOneOfLower) + ') ' +
|
||||
' AND "video"."id" = "videoTag"."videoId"' +
|
||||
')'
|
||||
)
|
||||
|
||||
this.joins.push('INNER JOIN "tagsOneOf" ON "video"."id" = "tagsOneOf"."videoId"')
|
||||
}
|
||||
|
||||
private whereTagsAllOf (tagsAllOf: string[]) {
|
||||
const tagsAllOfLower = tagsAllOf.map(t => t.toLowerCase())
|
||||
|
||||
this.and.push(
|
||||
'EXISTS (' +
|
||||
' SELECT 1 FROM "videoTag" ' +
|
||||
this.cte.push(
|
||||
'"tagsAllOf" AS (' +
|
||||
' SELECT "videoTag"."videoId" AS "videoId" FROM "videoTag" ' +
|
||||
' INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
|
||||
' WHERE lower("tag"."name") IN (' + createSafeIn(this.sequelize, tagsAllOfLower) + ') ' +
|
||||
' AND "video"."id" = "videoTag"."videoId" ' +
|
||||
' GROUP BY "videoTag"."videoId" HAVING COUNT(*) = ' + tagsAllOfLower.length +
|
||||
')'
|
||||
)
|
||||
|
||||
this.joins.push('INNER JOIN "tagsAllOf" ON "video"."id" = "tagsAllOf"."videoId"')
|
||||
}
|
||||
|
||||
private wherePrivacyOneOf (privacyOneOf: VideoPrivacyType[]) {
|
||||
|
Loading…
Reference in New Issue
Block a user