-
Notifications
You must be signed in to change notification settings - Fork 198
refactor: Optimize donor dashboard queries #7982
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
base: develop
Are you sure you want to change the base?
refactor: Optimize donor dashboard queries #7982
Conversation
84322b2
to
3c08642
Compare
@jfn4th thanks for the PR! 🙌 I'll admit, our donor dashboard queries are a bit outdated with some of our current performance updates we're making so this is a welcome update 😄. We're a small team and currently working on some big projects but i'll try to prioritize reviewing this within a week or so. |
3c08642
to
8c96700
Compare
Thanks for the info! I realized I missed that |
aa70ac6
to
550cb93
Compare
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.
Hey @jfn4th, great work. It will improve the performance of the Donor Dashboard. Thank you. I have a couple of suggestions, other than that, looks good 👍
* | ||
* @return object|null | ||
*/ | ||
private function queryDonationRevenueData($donorId, $selectClause) |
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.
The idea of passing SQL as a parameter makes me anxious 😅
I'd suggest refactoring this method to something like getRevenueDonationDataQuery
, which will return a QueryBuilder
object with a base query. Then, when you call it, it will look something like this:
$query = $this->getRevenueDonationDataQuery($ids);
$query->select('whatever');
$data = $query->getAll();
If you are not familiar with our QueryBuilder library, you can check it here https://github.com/impress-org/givewp/blob/develop/src/Framework/QueryBuilder/README.md
…eded getDonationAggregate method.
550cb93
to
7eb9977
Compare
Thanks @alaca for the feedback. I've moved to using the |
Description
This aims to greatly improve donor dashboard load times, particularly for sites with very large donation histories. A site we maintain with 130k donations and 6.3 million rows of donation meta was seeing timeouts when hitting
/wp-json/give-api/v2/donor-dashboard/donations
, and locally (M1 Pro Macbook Pro) was taking 30-40 seconds to resolve. This was due togetDonationIds
and calls togetDonationAggregate
each taking 5-8 seconds to run. Here, we remove an (as far as I am aware) unnecessary join towp_give_revenue
ingetDonationIds
and cache the result so we can reuse the IDs. Then consolidate the aggregate queries into a single query, taking advantage of the ID cache to remove the need for expensive joins. Altogether, this reduces the response time from 30-40 seconds to 1-2 seconds on my machine.Also replaces the usage of the deprecated
Give\ValueObjects\Money
class withGive\Framework\Support\ValueObjects\Money
updates method typedocs to reflect possibility of nullcount
,revenue
, andaverage
, and removes some stray whitespace characters.Affects
This affects the internal queries used in the
/wp-json/give-api/v2/donor-dashboard/donations
donor dashboard endpoint.Testing Instructions
/wp-json/give-api/v2/donor-dashboard/donations
Pre-review Checklist
@unreleased
tags included in DocBlocks