Skip to content

A write names the files it changed; the Studio reads those, not the root (#599) - #600

Merged
bubulux merged 2 commits into
mainfrom
fix/599-root-reads
Dec 4, 2026
Merged

bubulux merged 2 commits into
mainfrom
fix/599-root-reads

Conversation

@bubulux

@bubulux bubulux commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #599

What changed

Worker

  • A write that changed nothing but some files' own records names them in the root room's message: { type: "changed", files: [ids] }. Routes say so with changedOnly(ctx, …ids) (files.ts); index.ts passes the ids on when one root was touched and at most 16 files are named.
  • Named: PUT /api/files/:id (with the parent when an internal file is saved under its lock), PUT /api/files/:id/properties, POST /api/properties/set, PUT /api/canvases/:id/:part, PUT /api/photos/:id and PUT /api/photos/:id/:part (every photo that shares the image).
  • Not named, so read whole as before: a changed property definition (its values are refitted), a new file that others already point at (their reference is no longer missing), move, bin, restore, purge, empty bin, duplicate, release, and every other route.

Studio (files.ts)

  • loadFiles(root, ids) reads the named files with GET /api/files/:id and puts them into the root's list, kept in the server's order. What it cannot place (a file that left the list, not found, another root's, more than 16) reads the root.
  • Reads of one root run one after the other, so an earlier answer never replaces a later one; a root read that waits for its turn answers every further call.
  • A heard change is skipped when a read that began after it already covers it. The window's own change is therefore read once, not twice.
  • Autosaves (canvas, timeline, flows, shots, layouts, remotes), rename, body, new file, preset and device saves, property values and the import's preview step read their file instead of the root.

Decisions

  • The safe default is the wide message: a route that does not call changedOnly behaves as before.
  • The message format only gains a field, so a Studio from before this change keeps working against the new Worker (it reads the root on every changed).
  • The phone is untouched: it does not use the root socket.
  • No echo suppression by sender: the saving window still reads its file once (one cheap request), which keeps its copy of updated_at and the body right for the other windows on the page.

Checked

  • make check ran through.
  • Route test live-root.test.ts: every kind of named write is checked against the whole root read before and after (nothing but the named files may differ); the wider writes must stay unnamed.
  • Unit test apps/studio/src/files.test.ts: the store's reads with fetch, WebSocket and the timer stood in (12 cases); deliberate breaks of the store (never skipping a heard change, reads not in line) each made a test fail.
  • The browser tests still missing are listed for the Playwright suite in Testing: establish the baseline, add Studio end-to-end tests with Playwright (local and on staging) #543.
  • Route tests: projects.test.ts now checks which changes are named (a new file, a rename) and which are not (bin, move, a new file a shortcut already points at).
  • Clicked through locally (Playwright, project "Batch test 5211", Files app):
    • a folder made, renamed, and renamed three times in a burst by another client: one GET /api/files/:id each, shown in the list;
    • bin and purge by another client: one root read each;
    • rename through the context menu: PUT and one GET /api/files/:id;
    • to the recycle bin through the context menu: one root read (two before).

Not clicked through

  • The editors' autosaves (canvas, timeline, flows, shot, layouts, remotes), preset and device saves, property values and a photo import in the Studio; a photo arriving from the phone while the Studio is open.
  • Two browsers on the same project.
  • The effect on production's row count can only be seen after a deploy (D1 analytics, rows read per day).

🤖 Generated with Claude Code

bubulux and others added 2 commits December 4, 2026 18:03
…oot (#599)

After every write the Worker told the root's room `changed`, and every open
Studio read the whole root again (list and bin, about 1,200 D1 rows for a
project of 110 files), the saving window twice. With editors saving every
400 to 700 ms that came to 4.4 million rows read in a day by one person.

- Worker: a write that changed nothing but some files' own records names
  them, `{ type: "changed", files }` (PUT /api/files/:id, property values,
  a canvas's render, a photo and its images; at most 16, one root). A
  changed property definition, a new file others already point at, and
  every wider route stay unnamed.
- Studio: `loadFiles` reads named files one by one and puts them into the
  root's list; reads of a root run one after the other, a waiting root
  read answers every call, and a heard change is skipped when a read that
  began after it covers it (the window's own change no longer reads twice).
- Autosaves, renames, bodies, new files, values and the import's preview
  step read their file instead of the root.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…599)

- Worker route test (live-root.test.ts): every kind of named write is
  checked against the whole root, read before and after: nothing but the
  named files may differ. The writes that reach further (a new file
  something points at, a changed definition, move, copy, bin, restore,
  more than 16 files) must stay unnamed.
- Studio unit test (files.test.ts): the store's reads with fetch,
  WebSocket and the debounce timer stood in: named and plain changes,
  bursts, the window's own change read once, a change heard after a read
  began, a late answer of an earlier read, the fallbacks to the root, the
  socket coming back.
- files.ts imports ./api.ts by its file name so node --test can load it,
  and exports `watch`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@bubulux
bubulux merged commit 80988a9 into main Dec 4, 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.

Every write makes each open Studio read the whole root again: 4.4M D1 rows read in a day

1 participant