Skip to content

Commit ccc765d

Browse files
committed
remove cruft from commit code
1 parent 3e093e6 commit ccc765d

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

packages/fireproof/src/crdt-helpers.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,25 @@ export async function applyBulkUpdateToCrdt(
4242
updates: DocUpdate[]
4343
): Promise<CRDTMeta> {
4444
let result: Result | null = null
45-
// const batch = await Batch.create(tblocks, init.cid)
46-
// console.log('applyBulkUpdateToCrdt', updates.length)
4745
if (updates.length > 1) {
48-
// throw new Error('batch not implemented')
4946
const batch = await Batch.create(tblocks, head)
5047
for (const update of updates) {
5148
const link = await writeDocContent(tblocks, update)
5249
await batch.put(update.key, link)
5350
}
5451
result = await batch.commit()
55-
// console.log('batch result', result)
56-
} else {
57-
for (const update of updates) {
58-
const link = await writeDocContent(tblocks, update)
59-
result = await put(tblocks, head, update.key, link)
60-
const resRoot = result.root.toString()
61-
const isReturned = result.additions.some(a => a.cid.toString() === resRoot)
62-
if (!isReturned) {
63-
const hasRoot = await tblocks.get(result.root) // is a db-wide get
64-
if (!hasRoot) {
65-
throw new Error(
66-
`missing root in additions: ${result.additions.length} ${resRoot} keys: ${updates
67-
.map(u => u.key)
68-
.toString()}`
69-
)
70-
}
71-
}
72-
}
52+
} else if (updates.length === 1) {
53+
const link = await writeDocContent(tblocks, updates[0])
54+
result = await put(tblocks, head, updates[0].key, link)
7355
}
74-
if (!result) throw new Error('Missing result')
56+
if (!result) throw new Error('Missing result, updates: ' + updates.length)
7557

7658
if (result.event) {
77-
for (const { cid, bytes } of [...result.additions, ...result.removals, result.event]) {
59+
for (const { cid, bytes } of [
60+
...result.additions,
61+
...result.removals, // todo mute
62+
result.event
63+
]) {
7864
tblocks.putSync(cid, bytes)
7965
}
8066
}

0 commit comments

Comments
 (0)