sqlite-persistence: deleted rows keep their full value in the tombstone table forever (local-only collections)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, sqlite, typescript
Hướng nghiên cứu
Start with the tombstone INSERT that uses value = excluded.value in sqlite-core-adapter.js, and the mutation.original read in persisted.js that supplies the value. Reproduce with the Node snippet in the issue and check the sqlite_master tables for the value. Done means deleted rows keep only key and row version in tombstones, or a supported way to clear a local-only collection exists; this touches the sync and pruning logic, so design input from maintainers is needed first.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Versions: @tanstack/db, @tanstack/db-sqlite-persistence-core, @tanstack/node-db-sqlite-persistence, @tanstack/browser-db-sqlite-persistence and @tanstack/expo-db-sqlite-persistence 1.0.0-rc.1.2.
What happens
In a persisted collection with no sync (persistedCollectionOptions without sync, writes through utils.acceptMutations), deleting a row writes the row's whole value to the collection's tombstone table (t_<hash>). Nothing removes it later: a tombstone goes only when the same key is written again, on a truncate, or on a schema reset. A local-only collection can't truncate. The value also stays in applied_tx.replay_json until that table is pruned (1000 rows / 24 h by default).
So after delete(), the row is gone from the collection but still readable in the SQLite file (OPFS on the web, the app's files on phones).
Repro (Node)
import Database from 'better-sqlite3'
import { createCollection, createTransaction } from '@tanstack/db'
import { persistedCollectionOptions } from '@tanstack/db-sqlite-persistence-core'
import { createNodeSQLitePersistence } from '@tanstack/node-db-sqlite-persistence'
const database = new Database(':memory:')
const todos = createCollection(
persistedCollectionOptions<{ id: string; text: string }, string>({
id: 'todos',
getKey: (todo) => todo.id,
persistence: createNodeSQLitePersistence({ database }),
}),
)
await todos.preload()
const write = async (change: () => void) => {
const tx = createTransaction({
autoCommit: false,
mutationFn: async ({ transaction }) => {
await todos.utils.acceptMutations(transaction)
},
})
tx.mutate(change)
await tx.commit()
}
await write(() => todos.insert({ id: '1', text: 'private note' }))
await write(() => todos.delete('1'))
console.log(todos.size) // 0
for (const { name } of database.prepare(`SELECT name FROM sqlite_master WHERE type = 'table'`).all()) {
const rows = database.prepare(`SELECT * FROM "${name}"`).all()
if (JSON.stringify(rows).includes('private note')) console.log(name)
}
// applied_tx (replay_json has the inserted value)
// t_bicmgyk_5 {"key":"s:1","value":"{\"id\":\"1\",\"text\":\"private note\"}","row_version":2,"deleted_at":"…"}
Why it matters
- Privacy on shared devices. We clear a person's data at Sign Out by deleting their rows. With this behaviour the next person on the device (or a script on the site) can still read them from the file. We now delete the whole SQLite file at Sign Out instead.
- Growth. Every row that's written once and deleted (an outbox entry, say) leaves a tombstone for good, so the file grows without limit.
What would help
Any of these:
- Store only the key (and row version) in a tombstone, not the value.
- Prune tombstones (by count or age, like
appliedTxPruneMaxRows/appliedTxPruneMaxAgeSeconds) once no tab needs them for catch-up. - A supported way to empty a local-only collection completely, tombstones and
applied_txincluded (a local truncate), or to delete a collection's tables.
The relevant code is in sqlite-core-adapter.js: the tombstone INSERT … value = excluded.value for deletes, and the only DELETE FROM tombstone paths (a truncate, a re-write of the same key, a schema reset). The value comes from mutation.original in persisted.js.
- Ngôn ngữ chính
- TypeScript
- Star
- 4k
- Fork
- 286
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 105
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/db
-
extractSimpleComparisons returns value: null when the right side of a comparison isn't a literalĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`avg`, `min`, `max` and `sum` treat `null` values as `0`Có thể đã có người làm @oyobbeb đã nhận 11 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`Collection.currentStateAsChanges` JSDoc examples don’t match `CurrentStateAsChangesOptions`Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Two @tanstack/db tests time out under CPU load because a cold module import counts against the 5 s default timeoutCó thể đã có người làm @jp-knj đã nhận 23 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fb55/htmlparser2#2579 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue needs-review
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add Module DB RulesĐang mởdocumentation public
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
midnightntwrk/umbradb#65 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area/channels kind/bug priority/medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nanocoai/nanoclaw#4501 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docker images: plain X.Y.Z tag (e.g. 7.2.3) is never updated after the initial release buildĐang mởneeds verification
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 13 ngày