Little SQL optimization

This commit is contained in:
Chocobozzz 2018-01-11 14:30:27 +01:00
parent 6fd5ca1ec5
commit 6120941f59
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 11 additions and 17 deletions

View File

@ -94,15 +94,25 @@ enum ScopeNames {
[ScopeNames.WITH_ACCOUNT_DETAILS]: { [ScopeNames.WITH_ACCOUNT_DETAILS]: {
include: [ include: [
{ {
model: () => VideoChannelModel, model: () => VideoChannelModel.unscoped(),
required: true, required: true,
include: [ include: [
{
attributes: {
exclude: [ 'privateKey', 'publicKey' ]
},
model: () => ActorModel,
required: true
},
{ {
model: () => AccountModel, model: () => AccountModel,
required: true, required: true,
include: [ include: [
{ {
model: () => ActorModel, model: () => ActorModel,
attributes: {
exclude: [ 'privateKey', 'publicKey' ]
},
required: true, required: true,
include: [ include: [
{ {
@ -511,22 +521,6 @@ export class VideoModel extends Model<VideoModel> {
return VideoModel.findById(id) 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<VideoModel> = {
where: {
url
}
}
if (t !== undefined) query.transaction = t
return VideoModel.findOne(query)
}
static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
const query: IFindOptions<VideoModel> = { const query: IFindOptions<VideoModel> = {
where: { where: {