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 N+1 fetching payments in report #5595

Conversation

sauloperez
Copy link
Contributor

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

@sauloperez sauloperez self-assigned this Jun 12, 2020
pick e84e0ae Fix fatal error in reports helper for orders without payments
pick e725f33 Defend from an order w/o payments when building table
@filipefurtad0
Copy link
Contributor

Hey @sauloperez,
This relates to #5492, right? I'd test one after the other then.

@sauloperez
Copy link
Contributor Author

I can merge them together if that's going to make it easier for you by they touch two different reports.

@filipefurtad0
Copy link
Contributor

Thanks @sauloperez, not necessary. Thought this related to eventual performance issues introduced by the PR I mentioned. No need to merge them 👍

@filipefurtad0 filipefurtad0 self-assigned this Jun 16, 2020
@filipefurtad0 filipefurtad0 added the pr-staged-uk staging.openfoodnetwork.org.uk label Jun 16, 2020
@filipefurtad0
Copy link
Contributor

filipefurtad0 commented Jun 16, 2020

Hey @sauloperez ,

Tested this in Staging-UK, as superadmin.
In Payments by Type there is a decrease of around 3 sec. load time 🎉

However - and not introduced by this PR - the Payment Totals appears to be broken, across staging servers (tested in UK, FR, ES):

image

https://openfoodnetwork.slack.com/archives/CEF14NU3V/p1592334661341000

Perhaps related with #5572?

Update:
I see now I haven't checked Payment Totals, while testing PR #5573 - sorry for that. This needs a second look. I'm wondering if the original issue should be re-opened? Adding the feedback-label here.

@filipefurtad0 filipefurtad0 added feedback-needed and removed pr-staged-uk staging.openfoodnetwork.org.uk labels Jun 16, 2020
@sigmundpetersen
Copy link
Contributor

@filipefurtad0 there's an issue with snail on Payment Totals #4977.
It has been switching between s3 and s2. What do you think? S2?

payments = orders.includes(:payments).map do |order|
order.payments.select(&:completed?)
end.flatten

Copy link
Contributor

@Matt-Yorkley Matt-Yorkley Jun 17, 2020

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'))

Copy link
Contributor Author

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.

@sauloperez sauloperez merged commit e021910 into openfoodfoundation:master Jun 18, 2020
@sauloperez sauloperez deleted the improve-payments-report-performance branch June 18, 2020 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants