Skip to content

fix(ui): define each cached read once, so the developer report runs its own full check - #1060

Merged
ixuz merged 3 commits into
mainfrom
query-definitions
Nov 26, 2026
Merged

ixuz merged 3 commits into
mainfrom
query-definitions

Conversation

@ixuz

@ixuz ixuz commented Nov 26, 2026

Copy link
Copy Markdown
Member

What and why

The check made as an instance is opened (checkInstance) and the developer report's check of every document (validateInstance) were cached under one key, ["validation", url], and both stayed fresh until asked again. The workspace keeps its data check mounted while it shows the report. So the report showed the opening check from the cache, without the answer log, though validation.md says the developer report always checks it. "Validate again" then put the full report where the data check reads. An answer log month that didn't conform could then hold the instance back under "block the instance", though the opening check leaves the answer log out on purpose.

The cause was that each screen wrote out its own cached reads (key, use case and freshness), and nothing kept the sites of one key alike. This pull request has three commits:

  • The fix: each check has a key of its own under ["validation", url] (instanceCheck, fullValidation), so refreshing the instance's checks still makes both again, with the Studio's deck health. A regression test mounts both checks together. It fails on the shared key.
  • One definition per read: each read is defined once as TanStack Query's queryOptions, in packages/ui/src/ui/queries.ts (the app's reads and the Studio's shared ones) and apps/studio/src/ui/queries.ts (the Studio's own, built on the first, as the keys modules are).
    • A screen adds only what is its own: enabled, select, or a prefetch's own staleTime.
    • A definition given no argument to read with reads nothing (skipToken), so the guards and non-null assertions that only covered a missing argument are gone.
    • The nine factories already there move into the modules.
    • The release check's draft versions move to draftVersions.ts, so the Studio's queries module and releaseCheck.ts don't import each other.
    • No key's value changes.
  • The check: check:keys now also fails on a queryKey: property outside the two queries modules, in code that isn't a test. A QueryClient's filter of queries (an invalidation or a removal) still takes a key from queryKeys.

Where the sites of one key differed in freshness, one choice is made, with its reason in the definition's comment. Four of these choices change behavior:

  1. The Studio's Drafts and Transfer screens no longer read the deck arrangement again when the window takes the focus, as the other screens already don't. The arrangement is edited on screen before it's written.
  2. The deck list's scheduler invitation reads preferencesMisfit again on focus, as the preferences it describes are.
  3. The Studio's card inspector shows answers read in the last 30 s, as the statistics do. Every change still clears them.
  4. The Studio's instance health screen checks again on focus when its check failed or left a document unread, as the workspace's data check does.

docs/validation.md, docs/architecture.md (query keys), docs/testing.md (check:keys) and the pages that named the moved factories are updated. npm run check passes on each commit, and npm run lint:reuse passes.

Closes: #1059

ixuz added 3 commits November 26, 2026 17:19
…ng check

The check made as an instance is opened (checkInstance) and the
developer report's check of every document (validateInstance) were
cached under one key, ["validation", url], both kept fresh for good.
The workspace keeps its data check mounted while it shows the report,
so the report showed the opening check from the cache, without the
answer log, which validation.md says the developer report always
checks. And "Validate again" put the full report where the data check
reads, so an answer log month that doesn't conform could hold the
instance back under "block the instance", though the opening check
leaves the answer log out on purpose.

Each check now has a key of its own under ["validation", url]
(instanceCheck, fullValidation), so refreshing the instance's checks
still makes both again, with the Studio's deck health under it too.

Refs: #1059
Each screen wrote out the pod reads it caches: the query key, the use
case that fills it, and how long the result stays fresh. check:keys
made the key a single definition, but the read and its freshness were
still written at every site, and nothing kept the sites of one key
alike. That is how ["validation", url] came to be filled by two
different checks.

Each read is now defined once as TanStack Query's queryOptions, in
packages/ui/src/ui/queries.ts (Solid Memo's reads, and the ones the
Studio shares) and apps/studio/src/ui/queries.ts (the Studio's own,
built on the first, as the keys modules are). A screen spreads a
definition into useQuery, useQueries or a prefetch and adds only what
is its own: enabled, select, placeholderData, or a prefetch's or
fetch's own staleTime. A definition given no argument to read with
reads nothing (skipToken), so an enabled that only guarded a missing
argument goes, with its non-null assertions. The factories that were
already there (studyCountsQuery, courseStripQuery, libraryIndexQuery,
libraryUpgradeQuery, statisticsQuery, todayFiguresQuery,
libraryUpdatesQuery, releaseDraftQuery, deckHealthQuery) move into the
modules. Cache-only observers get definitions of their own
(foundDeckHealth, foundInstanceGraph) on the same keys. The release
check's draft versions and Markdown check move to draftVersions.ts, so
the Studio's queries module can use them without an import cycle.

Where the sites of one key differed in freshness, one choice is made:

- deckTree is never read again on focus: the arrangement is edited on
  the screen before it is written, and a read begun then could bring
  back the list as it was. The Studio's drafts and transfer screens
  no longer read the arrangement again when the window takes the
  focus.
- preferences: SchedulerInvitation's refetchOnWindowFocus: false goes.
  It had no effect: the workspace's own reads of the preferences,
  mounted beside it, read them again on focus.
- preferencesMisfit is read again on focus wherever it is shown, as
  the preferences it tells of are. The deck list's invitation now
  reads it again when the window takes the focus.
- cardAnswers is kept for STATISTICS_STALE_MS everywhere, as the
  statistics are: every change made clears it (keepStudyFiguresFresh),
  in the Studio too. The Studio's card inspector now shows answers
  read in the last half minute instead of reading them again.
- instanceCheck is read again on focus when it failed or left a
  document unread, on the Studio's instance health screen too, which
  before kept a check with data until asked.
- course: CourseStrip's 30 s is its prefetch's own staleTime (a
  course read in the last half minute isn't read again), so it stays
  at the prefetch; the read itself has one freshness.
- studyCounts: every site already used one factory.

The deck health screen's read afresh (forgetDeckCheck first) is the
definition's afresh option now, not a queryFn written at the screen.

Refs: #1059
Each cached read is now defined once in a queries module, with its
key, the use case that fills it and its freshness. Nothing kept a
screen from writing a read of its own again, with another use case or
freshness on the same key, which is how ["validation", url] came to
hold two different checks.

check:keys now also fails on a queryKey property of an object literal
outside packages/ui/src/ui/queries.ts and apps/studio/src/ui/queries.ts,
in code that is not a test. A QueryClient's filter of queries (an
invalidation, a removal, cancelQueries, matchQuery and the like) still
names its key by a function of queryKeys, so a queryKey given to one
is accepted. The rules on keys written out as arrays are unchanged,
and apply in the queries modules too.

Closes: #1059
@ixuz ixuz added bug Something isn't working enhancement New feature or request labels Nov 26, 2026
@ixuz
ixuz enabled auto-merge November 26, 2026 16:58
@ixuz
ixuz added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit d170327 Nov 26, 2026
57 checks passed
@ixuz
ixuz deleted the query-definitions branch November 26, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

1 participant