diff options
author | Chocobozzz <me@florianbigard.com> | 2020-02-21 14:11:11 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-02-21 14:11:11 +0100 |
commit | 49be0fd3255db54cf9b038bed792eb0de0faf591 (patch) | |
tree | 770ae6ddfa53f28a9b17f92d978023c87aefe9f3 /server/models | |
parent | c06be129506de9ac8d9910fed473c86724ca0e4e (diff) | |
download | PeerTube-49be0fd3255db54cf9b038bed792eb0de0faf591.tar.gz PeerTube-49be0fd3255db54cf9b038bed792eb0de0faf591.tar.zst PeerTube-49be0fd3255db54cf9b038bed792eb0de0faf591.zip |
Fix CPU usage on PostgreSQL
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video.ts | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index eacffe186..a91a7663d 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -136,8 +136,7 @@ import { | |||
136 | MVideoThumbnailBlacklist, | 136 | MVideoThumbnailBlacklist, |
137 | MVideoWithAllFiles, | 137 | MVideoWithAllFiles, |
138 | MVideoWithFile, | 138 | MVideoWithFile, |
139 | MVideoWithRights, | 139 | MVideoWithRights |
140 | MStreamingPlaylistFiles | ||
141 | } from '../../typings/models' | 140 | } from '../../typings/models' |
142 | import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file' | 141 | import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file' |
143 | import { MThumbnail } from '../../typings/models/video/thumbnail' | 142 | import { MThumbnail } from '../../typings/models/video/thumbnail' |
@@ -437,42 +436,31 @@ export type AvailableForListIDsOptions = { | |||
437 | } | 436 | } |
438 | 437 | ||
439 | if (options.followerActorId) { | 438 | if (options.followerActorId) { |
440 | let localVideosReq: WhereOptions = {} | 439 | let localVideosReq = '' |
441 | if (options.includeLocalVideos === true) { | 440 | if (options.includeLocalVideos === true) { |
442 | localVideosReq = { remote: false } | 441 | localVideosReq = ' UNION ALL SELECT "video"."id" FROM "video" WHERE remote IS FALSE' |
443 | } | 442 | } |
444 | 443 | ||
445 | // Force actorId to be a number to avoid SQL injections | 444 | // Force actorId to be a number to avoid SQL injections |
446 | const actorIdNumber = parseInt(options.followerActorId.toString(), 10) | 445 | const actorIdNumber = parseInt(options.followerActorId.toString(), 10) |
447 | whereAnd.push({ | 446 | whereAnd.push({ |
448 | [Op.or]: [ | 447 | id: { |
449 | { | 448 | [Op.in]: Sequelize.literal( |
450 | id: { | 449 | '(' + |
451 | [ Op.in ]: Sequelize.literal( | 450 | 'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' + |
452 | '(' + | 451 | 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' + |
453 | 'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' + | 452 | 'WHERE "actorFollow"."actorId" = ' + actorIdNumber + |
454 | 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' + | 453 | ' UNION ALL ' + |
455 | 'WHERE "actorFollow"."actorId" = ' + actorIdNumber + | 454 | 'SELECT "video"."id" AS "id" FROM "video" ' + |
456 | ')' | 455 | 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' + |
457 | ) | 456 | 'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' + |
458 | } | 457 | 'INNER JOIN "actor" ON "account"."actorId" = "actor"."id" ' + |
459 | }, | 458 | 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "actor"."id" ' + |
460 | { | 459 | 'WHERE "actorFollow"."actorId" = ' + actorIdNumber + |
461 | id: { | 460 | localVideosReq + |
462 | [ Op.in ]: Sequelize.literal( | 461 | ')' |
463 | '(' + | 462 | ) |
464 | 'SELECT "video"."id" AS "id" FROM "video" ' + | 463 | } |
465 | 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' + | ||
466 | 'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' + | ||
467 | 'INNER JOIN "actor" ON "account"."actorId" = "actor"."id" ' + | ||
468 | 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "actor"."id" ' + | ||
469 | 'WHERE "actorFollow"."actorId" = ' + actorIdNumber + | ||
470 | ')' | ||
471 | ) | ||
472 | } | ||
473 | }, | ||
474 | localVideosReq | ||
475 | ] | ||
476 | }) | 464 | }) |
477 | } | 465 | } |
478 | 466 | ||