Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.
This repository was archived by the owner on May 21, 2025. It is now read-only.

Improve performance rendering the Last Order Date column value on the WooCommerce > Subscriptions list table #782

Closed
@mattallan

Description

@mattallan

Description

On the WooCommerce > Subscriptions list table, we display a column for each Subscription's last order date:

Image

Each date value displayed in the Last Order Date column is calculated by:

  1. Getting the last order linked to the subscription
  2. 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.
  3. With the list of order IDs, we then take the latest order ID, and read it into memory
  4. 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

  1. 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.

  1. 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.

Image

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions