Skip to content

IMP Ignore block cache lock pairs in query findings - #72

Merged
allrude merged 1 commit into
mainfrom
lane-1/ignore-cache-lock-pairs
Nov 19, 2026
Merged

allrude merged 1 commit into
mainfrom
lane-1/ignore-cache-lock-pairs

Conversation

@allrude

@allrude allrude commented Nov 19, 2026

Copy link
Copy Markdown
Member

Magento's LockGuardedCacheLoader (db lock provider) issues SELECT GET_LOCK(?, ?) and SELECT RELEASE_LOCK(?) for every uncached block. On a cold category page that fired query.n_plus_one ("ran 20 times", call site resolves to LoggerProxy).

QueryAnalyzer::analyze() now skips these by SQL shape, so query.n_plus_one, query.repeated and repeat_count ignore them. The queries stay listed in the Queries tab.

Tests: lock pairs produce no findings; a real repeated SELECT beside lock pairs is still flagged.

GET_LOCK and RELEASE_LOCK pairs from LockGuardedCacheLoader repeat by design. QueryAnalyzer now skips them by SQL shape, so n_plus_one, repeated and repeat_count ignore them. They stay in the Queries tab.
@allrude

allrude commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review at 7bc1d76: PASS

All 5 checks (PHP 8.2 to 8.5, JS) pass at this head, no pending.

Skip scope: isCacheLock() matches ^\s*SELECT\s+(GET_LOCK|RELEASE_LOCK)\s*\( on the SQL only. Nothing else in the module references GET_LOCK, so no other user is hidden by name. By shape it also skips any other SELECT GET_LOCK(?, ?) caller (Magento's cron, indexer and queue lock backends use the same statement). That is acceptable for a repeat/N+1 finding, since a lock pair repeating is not a defect, but it cannot tell the cache loader from those. The rows stay in the Queries tab, and total_ms still includes them (the duration is added before the skip). The skipped queries get repeat_count 1 via the ?? 1 fallback in QueryCollector::payload().

Tests cover both directions: 20 lock pairs give no finding, and a real repeated SELECT beside lock pairs is still flagged.

Gating (not part of this diff, no change needed here): the analysis runs only on payload build, which happens after the request was allowed, so this change adds no cost when the bar is off. The recording hooks themselves check ProfileManager::isCollecting() first and do nothing when it is false. What does run on every request, bar off or not, is construction: LoggerPlugin and the event, block, observer and layout plugins take ProfileManager directly (not via Proxy), so ProfileManager and the collectors it is wired with are built on each request before Config::resolve() decides. Only HttpPlugin's arguments are proxied in etc/di.xml, which the comment there ("safe to leave installed because it is off by default") does not cover for these plugins. Pre-existing, separate from #72.

@allrude
allrude merged commit c9ca15e into main Nov 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant