-
-
Notifications
You must be signed in to change notification settings - Fork 730
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 N+1 fetching payments in report #5595
Remove N+1 fetching payments in report #5595
Conversation
Hey @sauloperez, |
I can merge them together if that's going to make it easier for you by they touch two different reports. |
Thanks @sauloperez, not necessary. Thought this related to eventual performance issues introduced by the PR I mentioned. No need to merge them 👍 |
Hey @sauloperez , Tested this in Staging-UK, as superadmin. However - and not introduced by this PR - the Payment Totals appears to be broken, across staging servers (tested in UK, FR, ES): https://openfoodnetwork.slack.com/archives/CEF14NU3V/p1592334661341000 Perhaps related with #5572? Update: |
@filipefurtad0 there's an issue with snail on Payment Totals #4977. |
payments = orders.includes(:payments).map do |order| | ||
order.payments.select(&:completed?) | ||
end.flatten | ||
|
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.
Looking at it again, I think something like this might be significantly more efficient:
payments = Spree::Payment.completed.where(order_id: orders.select('spree_orders.id'))
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.
Yes, I also wanted to get rid of this map
but it was so quick and non-distracting to do this that I thought to improve in a later PR.
What? Why?
Removes an N+1 related to payments
What should we test?
The payments report should work as expected while being a little faster.
Release notes
Remove N+1 from payments report
Changelog Category: Changed