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 n+1 possibilities in Promotion#blacklisted? #4275

Merged
merged 2 commits into from
Mar 2, 2022

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Feb 22, 2022

Description

This removes some n+1 possibilities in Spree::Promotion#blacklisted?. First, we go through a line items' variant to get its product as that is more likely to be preloaded, and second, we use Enumerable to find out whether any line item's products are non-promotionable rather than issuing a DB query for every promotion / every line item when using an order-level promotion rule.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • n/a I have updated Guides and README accordingly to this change (if needed)
  • n/a I have added tests to cover this change (if needed)
  • n/a I have attached screenshots to this PR for visual changes (if needed)

@tvdeyen tvdeyen self-requested a review February 22, 2022 08:39
@mamhoff mamhoff force-pushed the fix-promotion-n+1 branch 2 times, most recently from 510e3aa to b503abd Compare February 22, 2022 09:55
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Nice work. There are some specs failing that seem to be related. Mind looking at those?

@mamhoff mamhoff force-pushed the fix-promotion-n+1 branch 3 times, most recently from 2d3a266 to 3da9069 Compare February 24, 2022 11:36
The "blacklisted?" private method is called many times when
recalculating an order with many line items. When preloading an order
through ActiveRecord's `includes` or `preloads` feature, one will likely
preload a product through the line item's variant. Thus it's preferable
here to load the product through the variant.
When running this code, users have likely already loaded the line item's
variant's products. There's no need to run this DB query.
@mamhoff
Copy link
Contributor Author

mamhoff commented Feb 24, 2022

Done 💦

@waiting-for-dev waiting-for-dev merged commit 76d2df7 into solidusio:master Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants