Skip to content

Conversation

@marcusquinn
Copy link
Contributor

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

  1. Added caching to wu_calculate_mrr() to cache the Monthly Recurring Revenue calculation for 1 hour
  2. Optimized the MRR calculation to cache duration unit conversions to avoid repeated function calls
  3. Added caching to wu_calculate_arr() to cache the Annual Recurring Revenue calculation for 1 hour
  4. Added caching to wu_calculate_revenue() to cache revenue calculations based on date parameters
  5. Implemented a new wu_get_payments_sum() function that uses direct SQL queries for better performance
  6. Added caching to wu_calculate_refunds() to cache refund calculations based on date parameters
  7. Optimized wu_calculate_taxes_by_month() to reduce repeated method calls and improve caching
  8. Added caching to wu_calculate_signups_by_form() to cache signup statistics

Benefits

  • Reduced database queries for financial calculations
  • Improved dashboard loading time
  • Decreased server load when generating reports
  • Better user experience when viewing financial data
  • More efficient use of server resources

Testing

  1. View the dashboard and verify that financial statistics are displayed correctly
  2. Generate financial reports and verify that the data is accurate
  3. Check that performance is improved for repeated views of the same data

Performance Impact

  • Before: Each financial calculation executed multiple database queries on every request
  • After: Financial calculations are cached and optimized, reducing database load and improving response time

This optimization is particularly effective for sites with many memberships and payments, where financial calculations can be expensive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant