In https://github.com/Automattic/woocommerce-subscriptions-core/pull/171 we removed a section of our wcs_get_subscriptions() function which used get subscriptions by customer ID using the user's subscription cache and then setting this list of IDs in post__in to improve performance of this query.
While working on HPOS changes we removed the cache/post__in approach as it was no longer needed due to improvements with the new order tables, however, this now means non-HPOS stores are now inefficiently getting subscriptions by customer ID.
The code we removed:
// Maybe filter to a specific user
if ( 0 != $args['customer_id'] && is_numeric( $args['customer_id'] ) ) {
$users_subscription_ids = WCS_Customer_Store::instance()->get_users_subscription_ids( $args['customer_id'] );
$query_args = WCS_Admin_Post_Types::set_post__in_query_var( $query_args, $users_subscription_ids );
};
For large stores without HPOS, this can be a pretty significant hit to performance when using wcs_get_subscriptions() with the customer_id arg, so this PR brings back the user cache + post__in approach we had previously when HPOS is disabled.
Product impact
[ ] Added changelog entry (or does not apply)
[x] Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
[x] Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
[ ] Added deprecated functions, hooks or classes to the spreadsheet
Fixes #466
Description
In https://github.com/Automattic/woocommerce-subscriptions-core/pull/171 we removed a section of our
wcs_get_subscriptions()
function which used get subscriptions by customer ID using the user's subscription cache and then setting this list of IDs inpost__in
to improve performance of this query.While working on HPOS changes we removed the cache/post__in approach as it was no longer needed due to improvements with the new order tables, however, this now means non-HPOS stores are now inefficiently getting subscriptions by customer ID.
The code we removed:
For large stores without HPOS, this can be a pretty significant hit to performance when using
wcs_get_subscriptions()
with thecustomer_id
arg, so this PR brings back the user cache +post__in
approach we had previously when HPOS is disabled.Product impact