On my local site that only has ~1200 orders and ~300 parent orders, this way of filtering results in a posts in query with over 1200 characters. If you had over 100k orders and considering order numbers get longer the more you have, you can quickly see how this would result in a very large and inefficient query and in some cases a query that eventually fails.
This PR fixes this for HPOS sites (WP posts aren't eligible see note below) by using a join or subquery.
[!note]
On WP post stores this doesn't work because we're filtering the request query args directly via the request filter and there's no opportunity to filter the resulting database query clauses/args like we can on HPOS sites.
How to test this PR
On trunk go to WooCommerce → Orders
Using the order type filter, select "Subscription Parent" orders.
Make a note of the number of results.
Using the same order type filter, search for "Non subscription"
Make a note of the number of results.
Checkout this branch, confirm the results are the same for both order types.
Repeat for both HPOS and WP Post tables.
Product impact
[x] Added changelog entry (or does not apply)
[ ] Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
[ ] Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
[ ] Added deprecated functions, hooks or classes to the spreadsheet
Fixes #https://github.com/woocommerce/woocommerce-subscriptions/issues/4629
Description
On the Admin orders list table we allow users to filter the list table by subscription order types. eg renewal, parent, switch or non-subscription.
Up until now, to filter this list table by the parent orders we have used the
post__in
orpost__not_in
args.On large sites this does not scale because the query will eventually contain a long list of order IDs that will run into a query character limit.
eg
On my local site that only has ~1200 orders and ~300 parent orders, this way of filtering results in a posts in query with over 1200 characters. If you had over 100k orders and considering order numbers get longer the more you have, you can quickly see how this would result in a very large and inefficient query and in some cases a query that eventually fails.
This PR fixes this for HPOS sites (WP posts aren't eligible see note below) by using a join or subquery.
How to test this PR
trunk
go to WooCommerce → OrdersProduct impact