-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
@albanv it looks like CircleCI didn't run here for some reason. Could you push an empty commit and then remove it? |
97a0d65
to
f74cfa7
Compare
@aldesantis just did it, but the CI failed as well 😞 |
f74cfa7
to
0dd156d
Compare
There is something weird, the CI used here is the one from my org (epicery) and not solidus one |
@albanv I think you should opt-in to use external orbs in your |
@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! |
@albanv hey there! Just wanted to check if you had time to take a look, I'd love to merge this one, thanks! |
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.
351eefd
to
8c6b2fb
Compare
Sorry for the late reply, I don't work for Epicery anymore and so goes with solidus. |
@kennyadsl I'm not sure about the CircleCI current failures. Is it the same than before ? Does this PR needs more work before merging ? |
Nope, the only failing check is with Rails master (which is unreleased so it's not an issue). We are fine now, thanks @stem ! |
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.
Thanks!
Description
In
to_package
method, I've addedproduct
to includes.We have discovered that when we call
Spree::Stock::Estimator#calculate_shipping_rates
with ashipment.to_package
, it currently makes aproduct
DB query for eachvariant
.In our test, this subtle change has drastically reduced the number of queries to
product
by a factor equivalent tovariant
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: