Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
87 stars 31 forks source link

[Performance] WC_Subscriptions_Order->render_contains_subscription_column_content() adds extra performance overhead to orders management #731

Open prettyboymp opened 1 week ago

prettyboymp commented 1 week ago

WC_Subscriptions_Order->render_contains_subscription_column_content() adds two additional queries for each order listed on the orders admin listing page.

A couple of ways to make an improvement:

  1. The underlying code for wcs_order_contains_subscription() could be made more performant by avoiding the loading of any subscriptions (avoiding extra unneeded callbacks/filters), or at least avoiding the extra count query added on.
  2. Consider priming the data needed for the ->render_contains_subscription_column_content() for all orders being rendered at once in a single query rather than one at a time.
mattallan commented 1 week ago

Thanks @prettyboymp for raising these performance issues.

I've just pushed up #732 which improves the performance of our render_contains_subscription_column_content() using the first method you suggested.

FWIW I ran these changes on a test store with ~5000 orders and saw a decent reduction in the number of queries ran while viewing 200 orders on the WooCommerce > Orders page (could be wrong but it looked to be around ~50% reduction).

Consider priming the data needed for the ->render_contains_subscription_column_content() for all orders being rendered at once in a single query rather than one at a time.

I'm interested to dig deeper into this idea but will need to explore it a bit more to see what we can do.