• Resolved admirvirtua

    (@admirvirtua)


    Hello,

    We are having problems with our WooCommerce web shop. It was working fine for almost a year now, but today some SQL queries just get stuck and not processed, causing all 32 cpu cores to be used up.

    The query in question is:

    SELECT SQL_CALC_FOUND_ROWS  wp_posts.*, low_stock_amount_meta.meta_value AS low_stock_amount, MAX( product_lookup.date_created ) AS last_order_date FROM wp_posts  LEFT JOIN wp_wc_product_meta_lookup wc_product_meta_lookup ON wp_posts.ID = wc_product_meta_lookup.product_id  LEFT JOIN wp_postmeta AS low_stock_amount_meta ON wp_posts.ID = low_stock_amount_meta.post_id AND low_stock_amount_meta.meta_key = '_low_stock_amount'  LEFT JOIN wp_wc_order_product_lookup product_lookup ON wp_posts.ID = CASE
    				WHEN wp_posts.post_type = 'product' THEN product_lookup.product_id
    				WHEN wp_posts.post_type = 'product_variation' THEN product_lookup.variation_id
    			END WHERE 1=1  AND wp_posts.post_type IN ('product', 'product_variation') AND ((wp_posts.post_status = 'publish'))
    			AND wc_product_meta_lookup.stock_quantity IS NOT NULL
    			AND wc_product_meta_lookup.stock_status IN('instock','outofstock')
    			AND (
    				(
    					low_stock_amount_meta.meta_value > ''
    					AND wc_product_meta_lookup.stock_quantity <= CAST(low_stock_amount_meta.meta_value AS SIGNED)
    				)
    				OR (
    					(
    						low_stock_amount_meta.meta_value IS NULL OR low_stock_amount_meta.meta_value <= ''
    					)
    					AND wc_product_meta_lookup.stock_quantity <= 2
    				)
    			) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC, wp_posts.ID DESC LIMIT 0, 1

    We have no clue why this happens. And it never happened before.

Viewing 1 replies (of 1 total)
  • Thread Starter admirvirtua

    (@admirvirtua)

    I found that someone had the same problem. GitHub link.

    The problem is with analytics and latest WooCommerce version. Used this snippet. Pasted the code in a php file in the plugins folder, activated the plugin.

    The solution works, but this does disable analytics. So this is only a temporary solution.

Viewing 1 replies (of 1 total)
  • The topic ‘Low Stock Amount Query blocking server’ is closed to new replies.