-
Notifications
You must be signed in to change notification settings - Fork 106
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
fix(api): optimize performance in preUpdateMany #549
base: main
Are you sure you want to change the base?
fix(api): optimize performance in preUpdateMany #549
Conversation
if (oldState && oldState.category !== category) { | ||
const updatedNextBlocks = oldState.nextBlocks?.filter((nextBlock) => | ||
|
||
const oldStates: Block[] = await this.find({ _id: { $in: ids } }); |
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.
const oldStates: Block[] = await this.find({ _id: { $in: ids } }); | |
const oldStates = await this.find({ _id: { $in: ids } }); |
The find method will return the expected type Block[]
if (oldState && oldState.category !== category) { | ||
const updatedNextBlocks = oldState.nextBlocks?.filter((nextBlock) => | ||
|
||
const oldStates: Block[] = await this.find({ _id: { $in: ids } }); |
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.
@omarNaifer12 thanks for your contribution.
In addition to @yassinedorbozgithub comment, I suggest adding the criteria "different category" so that we avoid the "if" condition inside the loop.
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.
Thank you @marrouchi for the feedback.
Motivation
Updated the function prepareBlocksInCategoryUpdateScope to replace multiple findOne API calls with a single API call. Updated its tests accordingly
Fixes #536
Type of change:
Please delete options that are not relevant.
Checklist: