Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

omarNaifer12
Copy link

@omarNaifer12 omarNaifer12 commented Jan 9, 2025

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.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have performed a self-review of my own code
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

if (oldState && oldState.category !== category) {
const updatedNextBlocks = oldState.nextBlocks?.filter((nextBlock) =>

const oldStates: Block[] = await this.find({ _id: { $in: ids } });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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[]

@medchedli medchedli added the SWOC Social Winter of Code 2025 label Jan 13, 2025
if (oldState && oldState.category !== category) {
const updatedNextBlocks = oldState.nextBlocks?.filter((nextBlock) =>

const oldStates: Block[] = await this.find({ _id: { $in: ids } });
Copy link
Contributor

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.

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SWOC Social Winter of Code 2025
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🤔 [ISSUE] - (N +1 query problem) preUpdateMany block.repository.ts
6 participants