Performance improvements: rendering the Subscription Relationship column and checking if order is a renewal, switch etc. #732
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.
Part of #731
Description
When a merchant visits the WooCommerce > Orders list table, WooCommerce Subscriptions adds a custom "Subscription Relationship" column that displays an icon based on what type of order it is:
As reported in #731, our
render_contains_subscription_column_content()
function currently performs unnecessary queries which impacts overall site performance and performance when viewing/managing orders via the WooCommerce > Orders table. After looking at this function, I noticed a couple of issues that we should address:wcs_order_contains_subscription()
unnecessarily loads subscription objects into memory.wcs_order_contains_{order_type}()
functions are doing a lot when all we really need to do is check for meta on an order.This PR targets all of these issues:
wcs_is_parent_order( $order )
function which runs a much more performant query to check if an order is a parent order.wcs_order_contains_renewal()
,wcs_order_contains_resubscribe()
andwcs_order_contains_switch()
functions to use ourWCS_Related_Order_Store
class to check if the order belongs to a renewal, resubscribe and switch, without having to load subscription objects into memory.render_contains_subscription_column_content()
to call the updated/more performantwcs_order_contains_{order_type}( $order )
functions directly instead of going throughwcs_order_contains_subscription( $order_id, {order_type} )
wcs_order_contains_subscription()
to use more performant method for checking parent order.How to test this PR
Important
The changes in this PR impact potentially a lot of critical subscription flows. We should make sure these functions are heavily unit tested and test our critical flows to assess impact.
Product impact