Repository navigation
Group N+1 and duplicate queries into expandable cards - #1
Merged
Merged
Conversation
Boots the unmodified lens.js IIFE in a vm context with minimal DOM stubs and checks N+1 detection, row/summary rendering, the toggle-n1 filter, the stuck-filter fix, the truncated '≥' count and missing/null SQL. No npm dependencies; CI runs it with node --test.
… narrow layouts, a11y, stronger tests
… header, contrast, hardened timings and keys), more tests
…runs note; cover in-transaction badge
…view after collapsing, drop hover tint (contrast)
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.
What
The Queries panel only flagged a statement as Duplicate when its SQL and bindings were identical, so a real N+1 (the same query run once per row, with a different id each time) was never flagged. Opaque bindings made it worse, since they can't be compared at all. Repeated queries also filled the list with near-identical rows.
This PR groups repeated queries into compact, expandable cards and flags N+1 patterns. It is frontend-only (
resources/assets/lens.js, plus a README line and tests); there are no Rust or API changes.What you see
Each group is one card instead of N repeated rows:
5×overN+1(red) or2×overDUP(orange). The tooltip gives the run count and total time.Showing k of n runswhen a filter hides some of them. The runs slide open with a short staggered fade, and the header stays pinned while you scroll a long list.N+1 queriesbutton filters the list to N+1 groups, like the existing duplicates button. Combining both shows only runs that match both, which is usually nothing. A filter that has nothing to match on the selected request (for example the N+1 filter on a request with no N+1) is ignored instead of emptying the list.Definitions
N_PLUS_ONE_THRESHOLD). Opaque bindings can't be compared, so they count as varying. Two runs are more likely coincidence than a loop.Duplicatebadge.truncated_count > 0) both card types show the count as a lower bound (≥5×).MAX_RENDERED_QUERIES) counts cards and plain rows, so a huge group can't push distinct queries out of the list.Performance, accessibility, compatibility
prefers-reduced-motionturns the card transitions off.<button>witharia-expanded, a focus ring, and an accessible name such as "5 N+1 queries, 128µs total: select …"; the tile, sparkline, total and chevron arearia-hidden. Collapsed runs areinertandvisibility: hidden, so they are skipped by Tab and screen readers immediately.direction: ltr). Light-theme text uses darker--lens-*-strongtokens for contrast.styleattributes, so strict CSPs are fine. It usescolor-mix(),overflow: clip,inertandgrid-template-rowstransitions (all evergreen browsers; older ones just lose tints or the animation).Tests
tests/lens_n_plus_one.test.mjsloads the real, unmodifiedlens.jsin a Nodevmsandbox with minimal DOM stubs, so there are no npm dependencies. Its 30 tests cover the definitions and thresholds, duplicate and N+1 precedence, opaque bindings, truncation, missing SQL and odd timings, expand/collapse in place (includingaria-expanded,inertand focus), stable group ids across filters, re-renders and requests (including awkward SQL and hostile request ids), counts versus filtered runs, the render cap, sparkline bucketing, location handling, escaping of every user-controlled value, both filters and the stuck-filter fix. Breakinglens.jsin ~45 different ways makes at least one test fail each time. CI runs them withnode --test tests/*.test.mjs(Node 22) and lints with Biome.I also checked it in headless Chromium against a demo app (laravel-rust + SQLite): grouping, the expand animation, the filters, keyboard use, and narrow widths.
Notes
tests/**is in the crate'sincludelist, so the small.mjstest file ships with the published crate. Say if you'd rather exclude it.