Repository navigation
fix: refetch SQL query "All" options on every dashboard refresh - #3862
karl-power wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 2b90978 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
PR Review
2 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 0 P3 1 posted as inline comment(s) on the changed lines. 1 listed below. Findings outside the changed lines
Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. The refetch-on- 🟡 P2 -- recommended
🔵 P3 nitpicks (7)
Reviewers (9): correctness, testing, maintainability, project-standards, kieran-typescript, julik-frontend-races, agent-native, learnings-researcher, previous-comments. Pre-existing (not counted): the jscpd-flagged ~23-line clone between Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
Duplicate code analysis1 new clone introduced by this PR.
If one of these duplicates a helper that already exists, import it instead jscpd compared this branch against |
| mockQuery.mockResolvedValue({ | ||
| json: async () => ({ data: values.map(value => ({ value })) }), | ||
| }); | ||
|
|
There was a problem hiding this comment.
🟡 P2 — "doesn't refetch for an equal time range" checks the call count before any refetch could reach mockQuery
The queryFn first awaits renderValuesCall (useSqlQueryFilterValues.tsx:217) and only then calls getClickhouseClient().query. So a refetch fired by the effect on this rerender would not have called mockQuery yet when line 174 runs synchronously, and the test passes even if refreshKey were built from Date identity. Wait before asserting, for example with await waitFor(() => expect(result.current...isFetching).toBe(false)) or by flushing microtasks with await act(async () => {}), then check toHaveBeenCalledTimes(1).
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| useEffect(() => { | ||
| if (lastRefreshKeyRef.current === refreshKey) return; | ||
| lastRefreshKeyRef.current = refreshKey; | ||
| for (const result of results) { |
There was a problem hiding this comment.
🟡 P2 — Refetched "All" options aren't treated as loading, so tiles run twice per refresh with stale options first
For a query that ignores the time range, refetch keeps the cached data and leaves isLoading false. useExpandedSqlQueryVariables (line 117) therefore expands "All" right away with the old options at the new range, so tiles run at once. When the new values arrive, the expanded variables change and the tiles run again. Queries that read the time range get a new key and wait instead, which is the behaviour the 'waits for new options' test pins. To fix this, surface a refreshKey-triggered fetch as loading, for example by tracking isFetching after a key change and mapping it to isLoading in the expansion. Then tiles wait once for the fresh options, as they do for time-aware queries.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
E2E Test Results✅ All tests passed • 495 passed • 1 skipped • 1106s
Tests ran across 4 shards in parallel. |
b3b2426 to
2b90978
Compare
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
| }); | ||
|
|
||
| const lastRefreshKeyRef = useRef(refreshKey); | ||
| useEffect(() => { |
There was a problem hiding this comment.
🟡 P2 — On refresh, tiles still run once with the old "All" options for queries that ignore the time range
The refetch starts in an effect after the render that moved the range. Because the cached query already has data, isLoading stays false and useExpandedSqlQueryVariables expands "All" with the old values. Tiles therefore run for the new range with stale options, then run again when the refetch lands. Queries that use $__timeFilter behave differently: they get a new key and a new useQueries observer, so isLoading is true and tiles wait. To fix it, have the expansion report a filter as loading while a refresh-triggered refetch is pending: track the refresh key the data was fetched for and compare it with the current one, or check isFetching after a key change. Then add a test asserting unavailableVariables shows loading right after rerender({ dateRange: refreshedRange }).
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
Summary
A SQL query filter set to "All" now refetches its options on every dashboard refresh, so new values reach tiles. Stacked on #3861, which added "All" for SQL query filters.
staleTimenever triggers a fetch on its own. "All" kept the options from the first load, so new services or regions stayed out of tiles until the page reloaded.useSqlQueryFilterValuestakes arefreshKey: when it changes, every query refetches, and a request already in flight is reused. The dropdown and the page share one cache entry, so each refresh issues one options request per filter, not two, including for queries whose key changes with the range anyway.How to test
Use the test dashboard from #3861, and:
Minute, pick the connection, enterSELECT toString(toStartOfMinute(now())), set the variable name tominute, tick "Include "All" option" and save.Minute: $minute. Pick "All" in the Minute dropdown. The tile shows the current minute.References
Note
Low Risk
Dashboard filter caching/refresh behavior only; no auth, security, or data-write paths. Risk is mainly extra ClickHouse options queries on refresh.
Overview
SQL query dashboard filters with "All" selected now refetch their options on every dashboard refresh (time range change), even when the options SQL ignores
$__timeFilter, so tiles pick up newly appearing values instead of staying on the first load until a full page reload.useSqlQueryFilterValuesgains an optionalrefreshKey: when it changes, all options queries are refetched viarefetch({ cancelRefetch: false }), including queries whose react-query key is unchanged.useExpandedSqlQueryVariablespasses a key derived from the start/end timestamps of the dashboard date range (equal range by value does not refetch). Filter bar and tile expansion share the same query cache, so each refresh still issues one request per filter, not duplicate fetches.New integration tests cover refresh with time-agnostic SQL, time-filtered SQL, unchanged range, and dependent-variable changes.
Reviewed by Cursor Bugbot for commit 2b90978. Bugbot is set up for automated code reviews on this repo. Configure here.