GenerateBlocks Query Loop in editor overloading server via dynamic tags

  • Hi,

    I’ve had my server crash several times recently while editing posts, and my host has traced it to GenerateBlocks.

    While I had a post open in the block editor, my browser sent 393 requests to this endpoint in about 15 minutes:

    POST /wp-json/generateblocks/v1/dynamic-tag-replacements

    Each request took around 30 seconds and used about 160 MB of memory. That kept roughly a dozen PHP workers busy at once, which used up all the server’s RAM and caused it to crash.

    The posts where this happens contain a Query Loop showing WooCommerce products filtered by product tag (two tags). Around the same time, the error log also shows repeated REST requests from the editor with product_tag[terms][0]=62&product_tag[terms][1]=71 in the query, along with this warning:

    PHP Warning: Array to string conversion in wp-includes/class-wp.php on line 359

    Setup:
    – WordPress 7.1.4
    – GeneratePress with GP Premium 2.5.6
    – GenerateBlocks 2.5.0
    – GenerateBlocks Pro 2.8.0
    – WooCommerce 11.2.1
    – PHP 8.3, Cloudways

    Could you help me work out why the editor keeps calling this endpoint, and whether there’s a fix or a better way to set up the Query Loop to avoid it?

    Happy to share a link to an affected page or give admin access privately if that helps.

    Thanks,
    Tyler

  • Hi Tyler,

    The editor sends one request to that endpoint for each dynamic tag block, for each product shown in the Query Loop preview. GenerateBlocks 2.5.0 caps that preview at 50 products, so with around eight dynamic tag blocks per card you get roughly the 393 requests you measured. Each one loads WordPress and WooCommerce in full, which is where the 160 MB comes from. Once enough of those run at once the server runs out of RAM, and that’s what stretches each request out to 30 seconds and brings the box down.

    The quickest fix is to lower that preview cap. Add this as a snippet:

    add_filter( 'generateblocks_query_loop_editor_posts_cap', function() {
        return 3;
    } );

    generateblocks_query_loop_editor_posts_cap

    That shows three products in the editor preview instead of 50, which should take you from around 393 requests to roughly 24. It only affects what the editor previews — your front end is completely unaffected and still shows the full set.

    Two things that would help me look further:

    1. In your Cloudways panel, is Redis enabled for this application? GenerateBlocks caches these previews in the object cache, and without one that caching can’t persist between requests.
    2. Roughly how many blocks inside your loop item card use a dynamic tag?

    About that Array to string conversion warning — I’ve checked our source and that request isn’t coming from GenerateBlocks. Our query loop passes taxonomy filters in a different structure, and the two endpoints involved here don’t use URL parameters at all, so something else on the site is sending it.

    To find out what: open the editor with DevTools on the Network tab, type product_tag into the filter box, and look at the Initiator column for one of those requests. That’ll point to the plugin responsible. It’s unrelated to the crashes, so it’s worth chasing separately rather than now.

  • Hi,

    Thanks so much, that’s a brilliant explanation and really helpful.

    I’ve added the snippet to cap the editor preview at 3, and I’ve now enabled Redis for the application in Cloudways.

    To answer your second question, the loop only shows 3 products, and each card uses around eight dynamic tags: the tour dates, title, featured image, excerpt, duration and places available (ACF fields), price and the link.

    The loop was already set to 3 posts per page, so I don’t think the 50 product cap was the issue here. With 3 products and around eight tags each, one preview should be about 24 requests, so 393 suggests the preview re-rendered around 16 times. The loop was set to random order at the time, so I wonder if each render returned different products and triggered a fresh set of requests. I’ve switched it to menu order now.

    Thanks for checking the Array to string warning too. I’ll track that one down separately using the DevTools method you suggested.

    Thanks again,
    Tyler

  • Hi Tyler,

    Good catch on the cap — you’re right that it wasn’t the cause, and your arithmetic is spot on. With three products and eight tags you’d expect 24 requests per render, so 393 does mean roughly 16 renders.

    Your hunch about random order is correct, and I can confirm why from our source. When the Query Loop builds each card, it passes along the ID of the product in that position, and we use that ID as part of the key for caching the resolved tag previews — both in the browser and on the server. With random order, every time the query runs it returns a different three products, so every ID is new, so none of the cached previews can ever be reused. Each render starts from scratch with a fresh set of 24 requests.

    Switching to menu order is exactly the right fix. The query now returns the same products every time, so the previews cache properly and the repeat requests should stop.

    Enabling Redis was still worthwhile. Because previews are cached per product rather than per result set, each tour’s tags stay cached once they’ve been resolved, so the editor should feel noticeably quicker as you work.

    Worth saying as well: your live site was never affected by any of this. Dynamic tags are resolved once when a page renders on the front end, with no requests to that endpoint, so the crashes were only ever triggered by having the editor open.

    I’m raising the random order behavior with our development team, since the editor shouldn’t be able to generate requests without limit like that. If the editor behaves normally now, you’re all set. Do let me know if you see the request count climb again.

  • Hi,

    Thanks so much for confirming that, and for explaining exactly why it was happening. Really appreciate you digging into the source.

    I’ve made all the changes you recommended, and everything seems to be running well now. The editor feels much quicker and the server has been stable since with zero crashes.

    Glad it was useful to raise with the development team too. I’ll let you know if I see the request count climb again.

    Thanks again for the brilliant support,
    Tyler

  • Ok Tyler, no problem!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.