From 2c897999fe877c52c8f7458d8bbff6c9367b6587 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Jan 2018 15:22:36 +0100 Subject: Optimize SQL query that fetch actor outbox --- server/models/video/video.ts | 54 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 0d115367f..7af68b20b 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -459,7 +459,8 @@ export class VideoModel extends Model { }, include: [ { - model: VideoShareModel, + attributes: [ 'id' ], + model: VideoShareModel.unscoped(), required: false, where: { [Sequelize.Op.and]: [ @@ -475,28 +476,65 @@ export class VideoModel extends Model { }, include: [ { - model: ActorModel, - required: true + attributes: [ 'id', 'url' ], + model: ActorModel.unscoped() } ] }, { - model: VideoChannelModel, + model: VideoChannelModel.unscoped(), required: true, include: [ { - model: AccountModel, + attributes: [ 'name' ], + model: AccountModel.unscoped(), + required: true, + include: [ + { + attributes: [ 'id', 'url' ], + model: ActorModel.unscoped(), + required: true + } + ] + }, + { + attributes: [ 'id', 'url' ], + model: ActorModel.unscoped(), required: true } ] }, { + attributes: [ 'type' ], model: AccountVideoRateModel, - include: [ AccountModel ] + required: false, + include: [ + { + attributes: [ 'id' ], + model: AccountModel.unscoped(), + include: [ + { + attributes: [ 'url' ], + model: ActorModel.unscoped(), + include: [ + { + attributes: [ 'host' ], + model: ServerModel, + required: false + } + ] + } + ] + } + ] + }, + { + attributes: [ 'url' ], + model: VideoCommentModel, + required: false }, VideoFileModel, - TagModel, - VideoCommentModel + TagModel ] } -- cgit v1.2.3