Repository navigation
fix(sync): keep each account's encrypted activity within 1 MiB - #52
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Released clients pad every activity event to 64 KiB, which they upload as 87,610 bytes, so a month of activity took most of the database. Keep the newest events that fit in 1 MiB, which reads their stored length without loading payloads from overflow pages, and refuse to start with SQLite older than 3.43, which cannot.
aacc6a1 to
5faa06a
Compare
|
@coderabbitai rate limit 🤖 Posted automatically by coderabbit-review-queue |
|
Your plan includes PR reviews subject to rate limits. Reviews are available now. |
|
@coderabbitai review 🤖 Posted automatically by coderabbit-review-queue |
Action performed
|
Problem
sync_eventtook about 60% of the public instance's database (~915 MiB). Clients pad every activity event to one 64 KiB block, so each record of a few hundred bytes is stored as 87,610 bytes, and an account keeps up to 100 of them for 30 days. Activity is a broadcast that every device reads with its own cursor, so nothing deletes it on delivery.Change
sync_event::appendinserts a broadcast, then keeps the account's newest broadcasts, ordered bycreated_at, while they fit in 1 MiB and number at most 100. Released clients keep about their 11 newest padded events; clients that pad events in 1 KiB blocks (fix(sync): pad activity and device requests in 1 KiB blocks instead of 64 KiB OpenTubeX#3740) keep all 100 in about 160 KB.octet_length(payload), which reads the length from the record header instead of loading the payload from its overflow pages, so this adds no payload reads to the write transaction. SQLite gained that optimization in 3.43, so the server now refuses to start with an older SQLite and says why.The server can't read payloads, so end-to-end encryption is unchanged, and released clients keep working. On the public instance, this alone shrinks today's 11,570 events to 3,197 (about −72% of the table). Once clients pad in 1 KiB blocks, the table would hold about 18 MiB for today's event count. Freed pages are reused; the file itself only shrinks after a
VACUUM.Proof: extended
events_are_atomic_bounded_expiring_and_scoped_to_account_and_recipient(padded events are trimmed to the newest 11, small ones all kept, a delayed older upload does not evict newer events — this assertion fails when the trim treats the incoming event as newest);writes_and_polls_do_not_read_stored_event_payloadsfails withlength()and passes withoctet_length(); the startup check exits with its error when the probed function is missing.cargo test --workspace, clippy (SQLite and Postgres) and rustfmt pass.Reviewed with sol-loop: 3 rounds with gpt-6.2-sol on high.
Sol verdict: approved
Made with Claude Opus 5.5 in Claude Code, running in T3 Code.