-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Index Cleanup - Messages #3107
Index Cleanup - Messages #3107
Conversation
This reverts commit 3cd4a58.
async getFeed( | ||
environmentId: string, | ||
query: { channels?: ChannelTypeEnum[]; templates?: string[]; emails?: string[]; _subscriberId?: string } = {}, | ||
skip = 0, | ||
limit = 10 | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this one because it is not in use and can confuse other users of the repo.
@@ -22,10 +23,9 @@ export class MessageRepository extends BaseRepository<MessageDBModel, MessageEnt | |||
environmentId: string, | |||
subscriberId: string, | |||
channel: ChannelTypeEnum, | |||
query: { feedId?: string[]; seen?: boolean; read?: boolean } = {}, | |||
options: { limit: number; skip?: number } = { limit: 10 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed 'options' because it was not used internally in the method in order to create the query.
|
||
type MessageQuery = FilterQuery<MessageDBModel>; | ||
|
||
export class MessageRepository extends BaseRepository<MessageDBModel, MessageEntity> { | ||
export class MessageRepository extends BaseRepository<MessageDBModel, MessageEntity, EnforceEnvId> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added and update the env enforce to EnforceEnvId
…ection-indexes-refactor
…ection-indexes-refactor # Conflicts: # apps/api/src/app/events/usecases/message-matcher/message-matcher.usecase.ts # apps/api/src/app/events/usecases/send-message/send-message-in-app.usecase.ts
const message = await this.messageRepository.findOne({ | ||
transactionId, | ||
_environmentId: environment._id, | ||
_subscriberId: subscriber._id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added subscriberId so the query will fit the index in line 148 in message scheme file
@@ -52,10 +52,14 @@ export class MessageRepository extends BaseRepository<MessageDBModel, MessageEnt | |||
|
|||
if (query.seen != null) { | |||
requestQuery.seen = query.seen; | |||
} else { | |||
requestQuery.seen = { $in: [true, false] }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added so we always use the same index no matter if there is seen or read or not (with the createAt key)
/* | ||
* This index was initially created to optimize: | ||
* in app widget - feed query | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not sure about the comment, I just wanted to make sure the initial intent wasn't ambiguous and was documented so that if needed we could remove or update the indexes if needed.
_subscriberId: 1, | ||
_environmentId: 1, | ||
channel: 1, | ||
_feedId: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be removed, as it's optional in some places
messageSchema.index({ | ||
_parentId: 1, | ||
_environmentId: 1, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one is not relevant
transactionId: 1, | ||
_subscriberId: 1, | ||
_environmentId: 1, | ||
_messageTemplateId: 1, | ||
_templateId: 1, | ||
providerId: 1, | ||
channel: 1, | ||
_feedId: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transactionId: 1, | |
_subscriberId: 1, | |
_environmentId: 1, | |
_messageTemplateId: 1, | |
_templateId: 1, | |
providerId: 1, | |
channel: 1, | |
_feedId: 1, | |
transactionId: 1, | |
_subscriberId: 1, | |
_environmentId: 1, | |
providerId: 1, |
messageSchema.index({ | ||
_environmentId: 1, | ||
providerId: 1, | ||
channel: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
channel: 1, |
What change does this PR introduce?
Why? (Context)
We want to remove as many inefficient indexs and queries as possible.
Why was this change needed?
Stop using single indexes on the mongoose key implementation
Add compound indexes for common queries and patterns using MongoDB index best practices
Remove unused indexes from MongoDB atlas after implementing the new compound indexes
Other information (Screenshots)