Skip to content

Commit

Permalink
fix: trim message after persist
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley2058 committed Jan 22, 2025
1 parent 4495e1c commit 2618d3a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/y-socket-io/y-socket-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,12 @@ export class YSocketIO {
changed = tr.changed.size > 0
})
Y.transact(existDoc.ydoc, () => {
for (const msg of updates) Y.applyUpdate(existDoc.ydoc, msg)
for (const msg of updates) {
if (msg.length === 0) continue
Y.applyUpdate(existDoc.ydoc, msg)
}
for (const msg of awareness) {
if (msg.length === 0) continue
AwarenessProtocol.applyAwarenessUpdate(existDoc.awareness, msg, null)
}
})
Expand All @@ -429,7 +433,6 @@ export class YSocketIO {
this.debouncedPersist(namespace, doc.ydoc)
this.namespaceDocMap.get(namespace)?.ydoc.destroy()
this.namespaceDocMap.set(namespace, doc)
await this.client.trimRoomStream(namespace, 'index', nsp.sockets.size === 0)
}

/**
Expand All @@ -456,6 +459,7 @@ export class YSocketIO {
const doc = this.debouncedPersistDocMap.get(namespace)
if (!doc) return
await this.client.store.persistDoc(namespace, 'index', doc)
await this.client.trimRoomStream(namespace, 'index', true)
this.debouncedPersistDocMap.delete(namespace)
this.debouncedPersistMap.delete(namespace)
},
Expand Down

0 comments on commit 2618d3a

Please sign in to comment.