Optimize channel search query

pull/959/merge
Chocobozzz 2018-08-28 15:16:04 +02:00
parent 9ee92651f6
commit c3c2ab1c8b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 10 additions and 11 deletions

View File

@ -69,9 +69,9 @@ type AvailableForListOptions = {
// Only list local channels OR channels that are on an instance followed by actorId
const inQueryInstanceFollow = '(' +
'SELECT "actor"."serverId" FROM "actor" ' +
'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = actor.id ' +
'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
'SELECT "actor"."serverId" FROM "actorFollow" ' +
'INNER JOIN "actor" ON actor.id= "actorFollow"."targetActorId" ' +
'WHERE "actor"."id" = ' + actorIdNumber +
')'
return {
@ -253,15 +253,14 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
limit: options.count,
order: getSort(options.sort),
where: {
id: {
[ Sequelize.Op.in ]: Sequelize.literal(
'(' +
'SELECT id FROM "videoChannel" WHERE ' +
'lower(immutable_unaccent("name")) % lower(immutable_unaccent(' + escapedSearch + ')) OR ' +
'lower(immutable_unaccent("name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' +
')'
[Sequelize.Op.or]: [
Sequelize.literal(
'lower(immutable_unaccent("VideoChannelModel"."name")) % lower(immutable_unaccent(' + escapedSearch + '))'
),
Sequelize.literal(
'lower(immutable_unaccent("VideoChannelModel"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))'
)
}
]
}
}