Performance Optimization: Enhance financial calculation functions #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Performance Optimization: Enhanced Financial Calculation Functions
Description
This PR optimizes the financial calculation functions to improve performance by implementing caching and reducing redundant operations. These functions are used in the admin dashboard and reports, and can be expensive to calculate, especially on sites with many memberships and payments.
Changes Made
wu_calculate_mrr()to cache the Monthly Recurring Revenue calculation for 1 hourwu_calculate_arr()to cache the Annual Recurring Revenue calculation for 1 hourwu_calculate_revenue()to cache revenue calculations based on date parameterswu_get_payments_sum()function that uses direct SQL queries for better performancewu_calculate_refunds()to cache refund calculations based on date parameterswu_calculate_taxes_by_month()to reduce repeated method calls and improve cachingwu_calculate_signups_by_form()to cache signup statisticsBenefits
Testing
Performance Impact
This optimization is particularly effective for sites with many memberships and payments, where financial calculations can be expensive.