Skip to content

Keep a local copy of a game's database, read by primary key - #22

Merged
XopoIII merged 1 commit into
mainfrom
local-mirror
Oct 17, 2026
Merged

XopoIII merged 1 commit into
mainfrom
local-mirror

Conversation

@XopoIII

@XopoIII XopoIII commented Oct 16, 2026

Copy link
Copy Markdown
Owner

A live game spent D1's 5,000,000 free reads two days running on questions asked of D1 itself, and past the limit D1 refuses the ingest's inserts too. telemetryblox-mirror <database> <file> keeps a local SQLite copy with the kit's own schema and pulls it up by primary key: one row read a new batch, plus events_daily and actors whole. Every saved query then runs on the copy unchanged, for nothing. The copy keeps what the retention prunes.

  • worker/mirror/index.mjs (telemetryblox/mirror): openMirror, pull, parseWrangler, wranglerRemote
  • worker/bin/mirror.mjs: the command; prints what D1 counted as read
  • README "Reading a local copy", CHANGELOG 0.7.0, version 0.7.0 everywhere
  • The pipe and worker/dist unchanged, no migration

Evidence. lefthook run pre-commit --all-files clean; pre-push clean (119 specs, every mutant killed, package, Worker: 88 tests and the smoke). The seven new tests failed (four of seven) with the id cursor removed from the page query, and passed once it was restored.

Not done. No pull against a deployed D1: the account's reads were already spent today. wranglerRemote is proven over a stand-in that prints what wrangler d1 execute --json prints.

🤖 Generated with Claude Code

A live game spent D1's 5,000,000 free reads two days running on the questions asked of it, and
past the limit D1 refuses the ingest's inserts too, so reading the data lost it. The mirror keeps
a SQLite file on the developer's machine with the kit's own schema and brings it up to D1 by
primary key: a batch already in the copy is never read again, so a pull costs one row a new batch
plus the small tables events_daily and actors, and every question after it costs nothing. The copy
keeps what the retention prunes.

worker/mirror holds pull, openMirror, parseWrangler and wranglerRemote, exported as
telemetryblox/mirror; worker/bin/mirror.mjs is the telemetryblox-mirror command, which prints what
D1 counted as read. No runtime dependency: node:sqlite and child_process. The pipe and worker/dist
are unchanged and no migration is added. Version 0.7.0.

Checked: lefthook run pre-commit --all-files, every gate clean (check-worker: 88 tests and the
smoke). The seven new tests were seen failing (four of seven) with the id cursor taken out of the
page query, then passing with it restored. No pull ran against a deployed D1: the account's reads
were spent for the day.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XopoIII
XopoIII merged commit 0c9679a into main Oct 17, 2026
3 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.

1 participant