Fix: Growth Alert (Inline) N+1 database queries on WooCommerce shop/archive pages#133
Open
ZebaAfiaShama wants to merge 1 commit into
Conversation
Growth Alert (inline) hooks fire once per product on WooCommerce shop/archive pages, and each run re-queried the database for data that only varies by source. Restore request-level memoization in Inline::get_notifications_data(), keyed by source so different inline sources cannot receive each other's cached data. Measured on an 11-product archive with one active Growth Alert: Database->get_posts calls drop from 137 to 11 per page load with identical rendered output. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Growth Alert (inline) registers its render callback on
woocommerce_after_shop_loop_itemandwoocommerce_after_shop_loop_item_title, which fire once per product in shop/archive loops. Every callback run calledInline::get_notifications_data(), whose request-level cache was commented out — so the same product-independent data was re-queried from the database for every product on the page (classic N+1). Reported by a client whose shop pages slowed down, withNotificationX\Core\Database->get_postsdominating Query Monitor.This affects every site running NotificationX Pro with the WooCommerce module enabled — the queries fire even with zero Growth Alert campaigns created.
Fix
Restore request-level memoization in
Inline::get_notifications_data()(includes/Features/Inline.php), keyed by$sourceso different inline sources cannot receive each other's cached data (the likely reason the previous un-keyed cache was disabled). The computed result only varies by$source—$id/$settingsare only passed to thenx_inline_notifications_datashort-circuit filter — so per-request caching is safe. Per-product filtering still happens afterward in the extension render loop.The old public
$notifications_dataproperty keeps its previous shape/behavior for backward compatibility.Verification (Docker sandbox, WP + WooCommerce 10.9.1, NX 3.2.10 + Pro 3.1.2, 11 products, one active Growth Alert stock campaign)
Database->get_poststotalRendered Growth Alert markup is byte-identical before/after (verified by diffing the archive page HTML). With no inline campaign, per-page calls drop from 49 to 7.
Card
https://projects.startise.com/wp-admin/admin.php?page=fluent-boards#/boards/19/tasks/83239-Bug-Fix-%7C-Growth-Alert-(Inline
🤖 Generated with Claude Code