Skip to content

Commit

Permalink
Mutations that we can't apply should not fail the synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Nov 17, 2023
1 parent e10a3f3 commit cacae05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/backend/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ export class Database implements Syncable {
return this.store.transaction(async tx => {
const reHash = []
for (const mutation of mutations) {
const updateRows = await this.applyMutation(tx, mutation)
if (updateRows) reHash.push(updateRows)
try {
const updateRows = await this.applyMutation(tx, mutation)
if (updateRows) reHash.push(updateRows)
} catch (error) {
console.error(error)
console.warn(
`> could not apply mutation\n${JSON.stringify(mutation)}`
)
}
}
await Database.index(tx)
const changed = (
Expand Down
17 changes: 11 additions & 6 deletions src/backend/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@ export class Handler {
const {pending, db} = this.options
const meta = await db.meta()
if (!pending) return meta
const toApply = await pending.pendingSince(
meta.commitHash,
this.previewAuth()
)
if (!toApply) return meta
await db.applyMutations(toApply.mutations, toApply.toCommitHash)
try {
const toApply = await pending.pendingSince(
meta.commitHash,
this.previewAuth()
)
if (!toApply) return meta
await db.applyMutations(toApply.mutations, toApply.toCommitHash)
} catch (error) {
console.error(error)
console.warn('> could not sync pending mutations')
}
return db.meta()
}
}
Expand Down

0 comments on commit cacae05

Please sign in to comment.