From 6120941f599c1234c9974a7d33ff12faa88aaed0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Jan 2018 14:30:27 +0100 Subject: Little SQL optimization --- server/models/video/video.ts | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'server') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 6b825bf93..391568df4 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -94,15 +94,25 @@ enum ScopeNames { [ScopeNames.WITH_ACCOUNT_DETAILS]: { include: [ { - model: () => VideoChannelModel, + model: () => VideoChannelModel.unscoped(), required: true, include: [ + { + attributes: { + exclude: [ 'privateKey', 'publicKey' ] + }, + model: () => ActorModel, + required: true + }, { model: () => AccountModel, required: true, include: [ { model: () => ActorModel, + attributes: { + exclude: [ 'privateKey', 'publicKey' ] + }, required: true, include: [ { @@ -511,22 +521,6 @@ export class VideoModel extends Model { return VideoModel.findById(id) } - static loadAndPopulateAccount (id: number) { - return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS ]).findById(id) - } - - static loadByUrl (url: string, t?: Sequelize.Transaction) { - const query: IFindOptions = { - where: { - url - } - } - - if (t !== undefined) query.transaction = t - - return VideoModel.findOne(query) - } - static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { const query: IFindOptions = { where: { -- cgit v1.2.3