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

Remove a N+1 query on shipment model #3598

Merged
merged 1 commit into from
Sep 26, 2020

Conversation

albanv
Copy link
Contributor

@albanv albanv commented Apr 28, 2020

Description
In to_package method, I've added product to includes.
We have discovered that when we call Spree::Stock::Estimator#calculate_shipping_rates with a shipment.to_package, it currently makes a product DB query for each variant.
In our test, this subtle change has drastically reduced the number of queries to product by a factor equivalent to variant number.

Concerning the test to add, since I'm not very sure on how to proceed, I would like some guidance. (I've looked at estimator_spec and shipment_spec but since this issue arise when both are coupled, I'm not sure where is the place to start)

Checklist:

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

@aldesantis
Copy link
Member

@albanv it looks like CircleCI didn't run here for some reason. Could you push an empty commit and then remove it?

@albanv albanv force-pushed the remove-n+1-query branch from 97a0d65 to f74cfa7 Compare April 29, 2020 10:54
@albanv
Copy link
Contributor Author

albanv commented Apr 29, 2020

@aldesantis just did it, but the CI failed as well 😞

@albanv albanv force-pushed the remove-n+1-query branch from f74cfa7 to 0dd156d Compare April 29, 2020 14:06
@albanv
Copy link
Contributor Author

albanv commented Apr 29, 2020

There is something weird, the CI used here is the one from my org (epicery) and not solidus one

@kennyadsl
Copy link
Member

@albanv I think you should opt-in to use external orbs in your epicery/solidus CircleCI project.

@albanv albanv force-pushed the remove-n+1-query branch from 0dd156d to 351eefd Compare May 11, 2020 14:17
@aldesantis
Copy link
Member

@albanv looks like the CI is still failing here, any chance you can take a look? 🙏 I'm also happy to create another PR myself with your code if you want, just let me know!

@kennyadsl
Copy link
Member

@albanv hey there! Just wanted to check if you had time to take a look, I'd love to merge this one, thanks!

@kennyadsl kennyadsl added Needs Work changelog:solidus_core Changes to the solidus_core gem labels Sep 25, 2020
In `to_package` method, I've added `product` to includes.
We have discovered that `Spree::Stock::Estimator#calculate_shipping_rates`
currently make a product query for each `variant`.
In our test, this subtle change has drastically reduced
the number of query to `product` by a factor equivalent to `variant` number.
@albanv
Copy link
Contributor Author

albanv commented Sep 25, 2020

Sorry for the late reply, I don't work for Epicery anymore and so goes with solidus.
I have rebased my PR to trigger the CI. If it doesn't go through, I summon @stem to take my follow

@stem
Copy link
Contributor

stem commented Sep 25, 2020

@kennyadsl I'm not sure about the CircleCI current failures. Is it the same than before ? Does this PR needs more work before merging ?

@kennyadsl
Copy link
Member

Nope, the only failing check is with Rails master (which is unreleased so it's not an issue). We are fine now, thanks @stem !

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks!

@aldesantis aldesantis merged commit ae636e2 into solidusio:master Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants