Repository navigation
Description
Summary
The release-readiness review (.claude/reports/RELEASE_READINESS.md §1.2/§1.5/§8, Appendix A — local, gitignored) found the data layer's architecture excellent (fetch-once + stale-while-revalidate, warm-up on boot, quantized keys) but its pressure knobs untouched: a zero default staleTime makes every results-list mount redo real main-thread work, React Query's default 3× retry amplifies load during exactly a SahajCloud outage, hover prefetch can fire one request per row traversed, and the default 5-minute gcTime can evict the observer-less wholesale caches the whole architecture depends on. All four are cheap, local fixes in the query configuration layer.
Current behavior
src/config/query-client.ts:7-13sets onlyrefetchOnWindowFocus: false. The globalstaleTimeis 0, so every mount of the results list re-runs the derived events query — full-feed filter + per-event zod parse + distance sort. No network (the feed is cached) but real main-thread work per remount.eventsQuery(src/config/api/index.ts:37-51) sets nostaleTimeof its own.- React Query's default retry (3× exponential backoff) is untouched anywhere — no
retry:configuration exists insrc/(grep-verified). A SahajCloud outage means every client retries every query 3×, amplifying load exactly when the API struggles. NoAbortControllerusage repo-wide. - Hover prefetch is unthrottled:
src/components/molecules/EventListItem/EventListItem.tsx:84-87— the sharedactivatehandler firesprefetchEvent(event.id)on everymouseenter/focus. Dragging the cursor down a long list fires oneGET /events/:idper row traversed; the keys are distinct per event, so request dedup doesn't help. The report calls this "the most likely accidental request storm" (§1.5). - The default 5-min
gcTimecan evict the observer-less caches:['regions'],['geojson']and['event-titles', locale]are populated viaensureQueryDatain the imperative loaders (src/config/api/fetch.ts:147loadRegions,:183loadGeojson,:227loadEventTitles) which passstaleTimebut nogcTime— after idle, the wholesale feed refetches from scratch.GEOJSON_STALE_TIME/REGIONS_STALE_TIMEconstants already exist (src/config/query-client.ts:17,22) to hang this on.
Proposed changes
- Set a sane
staleTimeon the derived events query (eventsQuery) so a filter/list remount inside the window does zero recompute; consider a sensible global default inquery-client.tstoo. - Bound retries globally in
query-client.ts: 1–2 retries, capped delay, no retry on 4xx (the error kind/status is already recoverable —classifyError/atlasErrorinsrc/lib/report.tscarry it; a 4xx retry fails identically). - Throttle hover prefetch: a small dwell delay (~150 ms hover-intent timer) and/or a concurrency cap in
usePrefetchEvent(src/hooks/use-prefetch-event.ts) / theactivatehandler region ofEventListItem.tsx. Extract the dwell timer as a pure helper so it's unit-testable without a DOM. - Pin
gcTime(and confirmstaleTime) for the observer-less['regions']/['geojson']/['event-titles']caches, using the existing constants. Keep the loaders onensureQueryData({ revalidateIfStale: true })— do NOT switch them tofetchQuery(it blocks on the stale refetch; see.claude/rules/data-layer.md).
Acceptance criteria
- A filter/list remount within the stale window does zero recompute of the events query — verified by a query-fn call counter in a unit test.
- Retry config is bounded: at most 1–2 retries, capped delay, and none for 4xx responses — covered by a unit test on the retry predicate.
- A hover sweep across N rows fires ≤ a bounded number of prefetches — unit-tested with the dwell timer extracted pure (fake timers, no jsdom needed if the timer logic is pure).
-
['regions']and['event-titles', locale]survive an idle period longer than the default 5-mingcTime(pinned via the existing constants); the imperative loaders remainensureQueryData+revalidateIfStale: true. - No regression: a locale switch still refetches only the titles sliver (locale stays in its key); the touch-device idle warm-up (
usePrefetchEvents,EAGER_COUNT = 3) still fires; hover prefetch still warms before a deliberate click (dwell ≪ typical hover-to-click time). -
pnpm lint && pnpm typecheck && pnpm test:runpass. - Write an implementation report to
.claude/reports/<issue-number>-query-pressure.md— in the MAIN checkout at/Users/devindra/Documents/Projects/SahajAtlasWebeven when implementing from a worktree (the folder is gitignored) — covering what changed, what was deliberately NOT changed, and which readiness-report findings are resolved.
Files affected
src/config/query-client.tssrc/config/api/index.ts(query factories)src/hooks/use-prefetch-event.tssrc/components/molecules/EventListItem/EventListItem.tsx— the activate/prefetch handlers region only
Parallel implementation: this ticket OWNS the files above; sibling release-hardening tickets run concurrently. Avoid edits outside owned files except strictly additive ones — e.g. adding a gcTime option to the ensureQueryData calls in src/config/api/fetch.ts:147/183/227 counts as strictly additive and is permitted; restructuring those loaders is not.
References
.claude/reports/RELEASE_READINESS.md§1.2, §1.5, §1.6 (recommendation 3), §8, Appendix A (local, gitignored)- Data-layer caching rules:
.claude/rules/data-layer.md(stale-while-revalidate imperative reads; don't switch tofetchQuery) - Error classification for the 4xx retry predicate:
src/lib/report.ts(classifyError, issue feat(widget): classify errors and show only the actions that can help #89)
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
docs(data-layer): record the query pressure knobs and their invariants