From 186e1f7dff506a27cf372c529ad95b5e9d23004c Mon Sep 17 00:00:00 2001 From: Gosha Date: Wed, 17 Apr 2024 10:46:11 +0300 Subject: [PATCH] refactor: code index alignment --- libs/dal/src/repositories/change/change.schema.ts | 2 +- libs/dal/src/repositories/integration/integration.schema.ts | 6 +++++- libs/dal/src/repositories/layout/layout.schema.ts | 1 + .../message-template/message-template.schema.ts | 4 ++++ .../src/repositories/notification/notification.schema.ts | 5 ----- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libs/dal/src/repositories/change/change.schema.ts b/libs/dal/src/repositories/change/change.schema.ts index a3bc9f9ae6f..ad4e64605f6 100644 --- a/libs/dal/src/repositories/change/change.schema.ts +++ b/libs/dal/src/repositories/change/change.schema.ts @@ -23,7 +23,7 @@ const changeSchema = new Schema( type: Schema.Types.ObjectId, ref: 'Organization', }, - _entityId: Schema.Types.ObjectId, + _entityId: { type: Schema.Types.ObjectId, index: true }, _creatorId: { type: Schema.Types.ObjectId, ref: 'User', diff --git a/libs/dal/src/repositories/integration/integration.schema.ts b/libs/dal/src/repositories/integration/integration.schema.ts index fe689fea143..bec9530f52a 100644 --- a/libs/dal/src/repositories/integration/integration.schema.ts +++ b/libs/dal/src/repositories/integration/integration.schema.ts @@ -15,7 +15,6 @@ const integrationSchema = new Schema( _organizationId: { type: Schema.Types.ObjectId, ref: 'Organization', - index: true, }, providerId: Schema.Types.String, channel: Schema.Types.String, @@ -95,6 +94,11 @@ const integrationSchema = new Schema( schemaOptions ); +integrationSchema.index({ + _organizationId: 1, + active: 1, +}); + integrationSchema.plugin(mongooseDelete, { deletedAt: true, deletedBy: true, overrideMethods: 'all' }); // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/libs/dal/src/repositories/layout/layout.schema.ts b/libs/dal/src/repositories/layout/layout.schema.ts index 6a936ffb97b..4713a4b60b5 100644 --- a/libs/dal/src/repositories/layout/layout.schema.ts +++ b/libs/dal/src/repositories/layout/layout.schema.ts @@ -10,6 +10,7 @@ const layoutSchema = new Schema( _environmentId: { type: Schema.Types.ObjectId, ref: 'Environment', + index: true, }, _organizationId: { type: Schema.Types.ObjectId, diff --git a/libs/dal/src/repositories/message-template/message-template.schema.ts b/libs/dal/src/repositories/message-template/message-template.schema.ts index 514566289bb..04ec1cbc60c 100644 --- a/libs/dal/src/repositories/message-template/message-template.schema.ts +++ b/libs/dal/src/repositories/message-template/message-template.schema.ts @@ -89,6 +89,10 @@ messageTemplateSchema.index({ 'triggers.identifier': 1, }); +messageTemplateSchema.index({ + _parentId: 1, +}); + messageTemplateSchema.plugin(mongooseDelete, { deletedAt: true, deletedBy: true, overrideMethods: 'all' }); // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/libs/dal/src/repositories/notification/notification.schema.ts b/libs/dal/src/repositories/notification/notification.schema.ts index 206c658de1f..61f560233a7 100644 --- a/libs/dal/src/repositories/notification/notification.schema.ts +++ b/libs/dal/src/repositories/notification/notification.schema.ts @@ -10,26 +10,21 @@ const notificationSchema = new Schema( _templateId: { type: Schema.Types.ObjectId, ref: 'NotificationTemplate', - index: true, }, _environmentId: { type: Schema.Types.ObjectId, ref: 'Environment', - index: true, }, _organizationId: { type: Schema.Types.ObjectId, ref: 'Organization', - index: true, }, _subscriberId: { type: Schema.Types.ObjectId, ref: 'Subscriber', - index: true, }, transactionId: { type: Schema.Types.String, - index: true, }, channels: [ {