From 2618d3aca26b4d8183f70f583bc5ea1b0fa7004a Mon Sep 17 00:00:00 2001 From: stanley2058 Date: Wed, 22 Jan 2025 15:20:20 +0800 Subject: [PATCH] fix: trim message after persist --- src/y-socket-io/y-socket-io.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/y-socket-io/y-socket-io.js b/src/y-socket-io/y-socket-io.js index f2520cd..1cf6b64 100644 --- a/src/y-socket-io/y-socket-io.js +++ b/src/y-socket-io/y-socket-io.js @@ -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) } }) @@ -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) } /** @@ -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) },