Automattic / woocommerce-subscriptions-core

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

Use user's subscriptions cache data when querying customer IDs in wcs_get_subscription() on stores not using HPOS #466

Closed mattallan closed 1 year ago

mattallan commented 1 year ago

Describe the bug

In https://github.com/Automattic/woocommerce-subscriptions-core/pull/171 we removed this block of code inside our wcs_get_subscriptions() function as it was no longer necessary with HPOS enabled:

// 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 significant hit to performance when querying for subscriptions by customer_id so it should still be used when HPOS is disabled.

Acceptance criteria

  1. For stores with HPOS disabled, bring back the above approach of using the user's subscription cache data + post__in query args when querying by customer ID
  2. For stores with HPOS enabled, continue to query using customer_id and remove the need for the users subscription cache.