• Hi,

    We are seeing overlapping executions of sws_bulk_index_recurring_hook on a WooCommerce site during/after product imports.

    The callback YSWS\Core\DB_Index\recurring_bulk_index_posts() calls bulk_index_posts() without a concurrency guard. When multiple wp-cron.php processes overlap, they all run the same expensive wp_posts /
    wp_postmeta query for sws_indexed, causing high MariaDB CPU and many duplicate concurrent queries.

    As a temporary mitigation, we wrapped recurring_bulk_index_posts() with a MySQL GET_LOCK(…, 30) / RELEASE_LOCK() guard, and the duplicate query pile stopped after clearing stale cron processes.

    Could you add an official lock/concurrency guard around the recurring bulk indexing cron, or advise on the recommended way to prevent overlapping sws_bulk_index_recurring_hook runs?

    This is the patch we applied temporarily

      +++ /wp-content/plugins/smart-woocommerce-search/inc/core/db-index.php
    @@ -204,7 +204,32 @@
    * @return void
    */
    function recurring_bulk_index_posts() {
    - bulk_index_posts();
    + global $wpdb;
    +
    + $lock_name = 'homepro_sws_bulk_index';
    + $got_lock = (int) $wpdb->get_var(
    + $wpdb->prepare(
    + 'SELECT GET_LOCK(%s, %d)',
    + $lock_name,
    + 30
    + )
    + );
    +
    + if ( 1 !== $got_lock ) {
    + error_log( 'Smart WooCommerce Search recurring bulk index skipped: lock not acquired.' );
    + return;
    + }
    +
    + try {
    + bulk_index_posts();
    + } finally {
    + $wpdb->get_var(
    + $wpdb->prepare(
    + 'SELECT RELEASE_LOCK(%s)',
    + $lock_name
    + )
    + );
    + }
    }


    Thank you


Viewing 1 replies (of 1 total)
  • Plugin Author YummyWP

    (@yummy-wp)

    Hello,

    Thank you for pointing out this specific issue and for sharing your solution.

    I’ll review it and update the plugin to prevent overlapping cron job executions.

    I appreciate your feedback and contribution.

    Thanks,
    Stanislav

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.