Home Forums Plugins WooCommerce Product Builder Product Builder Rankmath makes redis flush cache every second

Product Builder Rankmath makes redis flush cache every second

  • Author
    Posts
  • #245581

    Stonehouse Security
    Participant

    Hello VillaTheme team,

    We love the Product Builder, but we’re hitting a serious performance issue when it’s active together with Rank Math’s URL strip features.

    Environment
    WordPress: (latest)
    WooCommerce: 10.2.1
    Product Builder for WooCommerce: 2.3.5
    Rank Math SEO: 1.0.254 ( PRO 3.0.68)
    Object Cache Pro (Redis): 1.24.5

    Builder slug (permalink base) set to standard: “product-builder”

    -Rank Math settings (must have for our SEO)

    -Remove product base

    Remove category base

    Remove parent slug

    Problem:
    As soon as Product Builder is active, every frontend request triggers a rewrite/flush sequence which ends up flushing our Redis object cache via Rank Math’s Permalink_Watcher. We see 3–5 flushes per second in Object Cache Pro logs and high CPU.

    Sample stack from the log:

    RankMathWooCommercePermalink_Watcher->add_rewrite_rules,
    apply_filters(‘rewrite_rules_array’),
    WP_Rewrite->rewrite_rules,
    WP_Rewrite->refresh_rewrite_rules,
    WP_Rewrite->flush_rules

    Reproduction

    Enable the three Rank Math “strip” options above. (we had it for years)
    Activate Product Builder
    Observe Redis/Object Cache Pro logs: constant flushes; CPU spikes.
    Deactivate Product Builder or disable Rank Math strips → the issue stops.

    Likely root cause (file/code reference)
    In woo-product-builder/admin/admin.php, class VI_WPRODUCTBUILDER_F_Admin_Admin, method init():

    The CPT woo_product_builder is registered with a custom slug (from option wpb2205_cpt_base), and then flush_rewrite_rules() is called unconditionally at the end of init().

    Because init() runs on every request (including frontend), this flushes rewrite rules constantly. Rank Math hooks rewrite_rules_array and calls wp_cache_flush() in its watcher, so we end up with a permanent cache-flush storm.

    Expected
    Rewrite rules should be flushed only: on plugin activation/deactivation (you already do this in the main plugin file), and/orwhen the builder base slug changes (on Permalinks screen), not on every request.

    Suggested fix? (one of the following? not my ideas)

    Move/remove the unconditional flush from VI_WPRODUCTBUILDER_F_Admin_Admin::init().

    Flush only when the slug is changed on Permalinks page, e.g. inside woo_product_builder_load_permalinks() after update_option(‘wpb2205_cpt_base’, …):

    public function woo_product_builder_load_permalinks() {
    if ( isset($_POST[‘wpb2205_cpt_base’]) ) {
    update_option(‘wpb2205_cpt_base’, sanitize_title_with_dashes($_POST[‘wpb2205_cpt_base’]));
    flush_rewrite_rules(false); // flush only when base changed
    }
    }

    Or gate it with a transient so it cannot run on every request?

    We have no temporary work around, but decided to shut off redis in production for now.

    I am adding the staging site and links for your convenience if you can either patch it or possibly make some kind of work around.

    Thanks a lot!

    – Everyone in our team

You must be logged in to see replies to this topic. Click here to login or register