]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix CPU usage on PostgreSQL
authorChocobozzz <me@florianbigard.com>
Fri, 21 Feb 2020 13:11:11 +0000 (14:11 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 21 Feb 2020 13:11:11 +0000 (14:11 +0100)
server/models/video/video.ts

index eacffe1864156d84d84e0cc2ee817c892cd354ae..a91a7663d24f5d1581e64e9c6a2212c8b766cd23 100644 (file)
@@ -136,8 +136,7 @@ import {
   MVideoThumbnailBlacklist,
   MVideoWithAllFiles,
   MVideoWithFile,
-  MVideoWithRights,
-  MStreamingPlaylistFiles
+  MVideoWithRights
 } from '../../typings/models'
 import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
 import { MThumbnail } from '../../typings/models/video/thumbnail'
@@ -437,42 +436,31 @@ export type AvailableForListIDsOptions = {
     }
 
     if (options.followerActorId) {
-      let localVideosReq: WhereOptions = {}
+      let localVideosReq = ''
       if (options.includeLocalVideos === true) {
-        localVideosReq = { remote: false }
+        localVideosReq = ' UNION ALL SELECT "video"."id" FROM "video" WHERE remote IS FALSE'
       }
 
       // Force actorId to be a number to avoid SQL injections
       const actorIdNumber = parseInt(options.followerActorId.toString(), 10)
       whereAnd.push({
-        [Op.or]: [
-          {
-            id: {
-              [ Op.in ]: Sequelize.literal(
-                '(' +
-                'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' +
-                'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
-                'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
-                ')'
-              )
-            }
-          },
-          {
-            id: {
-              [ Op.in ]: Sequelize.literal(
-                '(' +
-                'SELECT "video"."id" AS "id" FROM "video" ' +
-                'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
-                'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' +
-                'INNER JOIN "actor" ON "account"."actorId" = "actor"."id" ' +
-                'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "actor"."id" ' +
-                'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
-                ')'
-              )
-            }
-          },
-          localVideosReq
-        ]
+        id: {
+          [Op.in]: Sequelize.literal(
+            '(' +
+            'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' +
+            'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
+            'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
+            ' UNION ALL ' +
+            'SELECT "video"."id" AS "id" FROM "video" ' +
+            'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
+            'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' +
+            'INNER JOIN "actor" ON "account"."actorId" = "actor"."id" ' +
+            'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "actor"."id" ' +
+            'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
+            localVideosReq +
+            ')'
+          )
+        }
       })
     }