Problem: awful delays (100+ seconds) on Stock Central on a site with a large number of orders.
wp-content/plugins/atum-stock-manager-for-woocommerce/classes/Inc/Helpers.php
public static function get_sold_last_days()
the resulting MySQL query executed for EACH product in the list (sold items for 30 days setting):
SELECT SUM(mt_qty.meta_value) AS QTY
FROM wp_posts AS orders
LEFT JOIN wp_woocommerce_order_items AS items ON (orders.ID = items.order_id)
LEFT JOIN wp_woocommerce_order_itemmeta AS mt_id ON (items.order_item_id = mt_id.order_item_id)
LEFT JOIN wp_woocommerce_order_itemmeta AS mt_qty ON (items.order_item_id = mt_qty.order_item_id AND mt_qty.meta_key = ‘_qty’)
WHERE orders.ID IN (
SELECT ID FROM wp_posts
WHERE post_date_gmt >= ‘2021-07-19 08:56:17’ AND post_date_gmt <= ‘2021-08-18 08:56:17’
AND post_type = ‘shop_order’ AND post_status IN (‘wc-processing’, ‘wc-completed’)
)
AND mt_id.meta_key IN (‘_product_id’, ‘_variation_id’)
AND mt_id.meta_value = 356253
GROUP BY mt_id.meta_value
HAVING (QTY IS NOT NULL)
Note the inner SELECT in WHERE IN which in our case results in a list of 6000+ order IDs, most of them unrelated to the product that the query is executed for.
If you reduce the number of days for sold calculation in plugin settings, you will observe a dramatic reduction of query execution times as the order list is shorter.
This is a major design flaw, please fix ASAP.