Skip to content

Commit

Permalink
merge yjs updates before persisting
Browse files Browse the repository at this point in the history
  • Loading branch information
vieiralucas committed Dec 6, 2024
1 parent 35ed397 commit 1d36f89
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/api/src/yjs/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,15 +682,30 @@ export class WSSharedDocV2 {
'Enqueuing Yjs update for publishing'
)
await this.serialUpdatesQueue.add(async () => {
const updates = this.pendingUpdates
let updates = this.pendingUpdates
this.pendingUpdates = []
if (updates.length === 0) {
return
}

try {
const update = Y.mergeUpdates(updates)
updates = [update]
} catch (err) {
logger().error(
{
id: this.id,
documentId: this.documentId,
workspaceId: this.workspaceId,
err,
},
'Failed to merge Yjs updates, persisting individually'
)
}

const pubsubChannel = this.getPubSubChannel()
try {
const updateIds = await this.persistor.persistUpdates(this, updates)
const updateIds = await this.persistor.persistUpdates(this, [update])
for (const updateId of updateIds) {
await publish(
pubsubChannel,
Expand Down

0 comments on commit 1d36f89

Please sign in to comment.