1
0
Fork 0

Optimize channel search query

This commit is contained in:
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

View file

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