]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Optimize channel search query
authorChocobozzz <me@florianbigard.com>
Tue, 28 Aug 2018 13:16:04 +0000 (15:16 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 28 Aug 2018 13:16:04 +0000 (15:16 +0200)
server/models/video/video-channel.ts

index 7d717fc68fd21f1b6bff6abbb8242cb0a5e05ebb..e70e525153c0351bf40bfd7bc6f2ff89d2402132 100644 (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 + '))'
           )
-        }
+        ]
       }
     }