Description
Description
On the WooCommerce > Subscriptions list table, we display a column for each Subscription's last order date:
Each date value displayed in the Last Order Date column is calculated by:
- Getting the last order linked to the subscription
- To fetch this, we need to first fetch the list of parent, renewal & switch order IDs linked to the subscription. We store this list of related order IDs on the subscription in a cache, but if that cache doesn't exist, we run separate order meta queries to fetch all orders that are linked to this subscription.
- With the list of order IDs, we then take the latest order ID, and read it into memory
- Get this order's
date_created
value
Needing to calculate this value for every subscription rendered on the WooCommerce > Subscriptions page adds unnecessary performance burden, not to mention the queries required to sort by this column as well.
Possible Solutions
- On large sites, don't populate the Last Order Date column
This is not an ideal solution, but more of a temporary short-term fix.
In Subscriptions we have a helper function (see wcs_is_large_site()
) that categorises large sites as those with 3,000+ subscriptions. To increase the performance of this page, we could prevent this column from being loaded/calculated on large subscription stores. If stores want it back, we could add a filter to include it.
Important
Sorting by this column allows merchants to find the most recently renewed subscriptions, so it might introduce a bad experience to merchants if we just remove this column entirely.
- Store the
last_order_date
as metadata on the subscription.
For our other date fields (i.e. next payment, trial end, end date etc), even though these dates are already calculated and stored in Action Scheduler as pending scheduled actions, we also store these values as metadata on the subscription and keep these values in sync.
The idea of this solution would be to calculate and store this value in metadata and then as part of our related orders handling, we could keep this value in sync.
Storing this value as metadata would reduce the need to fetch and instantiate the last order, but also improve our queries that sort the table by last order date.
Activity