@@ -18,11 +18,11 @@ const logSocketIO = createModuleLogger('@y/socket-io/server')
1818const PERSIST_INTERVAL = number . parseInt ( env . getConf ( 'y-socket-io-server-persist-interval' ) || '3000' )
1919const REVALIDATE_TIMEOUT = number . parseInt ( env . getConf ( 'y-socket-io-server-revalidate-timeout' ) || '60000' )
2020
21- process . on ( 'SIGINT' , function ( ) {
21+ process . on ( 'SIGINT' , function ( ) {
2222 // calling .shutdown allows your process to exit normally
23- toobusy . shutdown ( ) ;
24- process . exit ( ) ;
25- } ) ;
23+ toobusy . shutdown ( )
24+ process . exit ( )
25+ } )
2626
2727/**
2828 * @typedef {import('socket.io').Namespace } Namespace
@@ -411,8 +411,12 @@ export class YSocketIO {
411411 changed = tr . changed . size > 0
412412 } )
413413 Y . transact ( existDoc . ydoc , ( ) => {
414- for ( const msg of updates ) Y . applyUpdate ( existDoc . ydoc , msg )
414+ for ( const msg of updates ) {
415+ if ( msg . length === 0 ) continue
416+ Y . applyUpdate ( existDoc . ydoc , msg )
417+ }
415418 for ( const msg of awareness ) {
419+ if ( msg . length === 0 ) continue
416420 AwarenessProtocol . applyAwarenessUpdate ( existDoc . awareness , msg , null )
417421 }
418422 } )
@@ -426,10 +430,9 @@ export class YSocketIO {
426430 changed = getDoc . changed
427431 }
428432 assert ( doc )
429- this . debouncedPersist ( namespace , doc . ydoc )
433+ if ( changed ) this . debouncedPersist ( namespace , doc . ydoc )
430434 this . namespaceDocMap . get ( namespace ) ?. ydoc . destroy ( )
431435 this . namespaceDocMap . set ( namespace , doc )
432- await this . client . trimRoomStream ( namespace , 'index' , nsp . sockets . size === 0 )
433436 }
434437
435438 /**
@@ -456,6 +459,7 @@ export class YSocketIO {
456459 const doc = this . debouncedPersistDocMap . get ( namespace )
457460 if ( ! doc ) return
458461 await this . client . store . persistDoc ( namespace , 'index' , doc )
462+ await this . client . trimRoomStream ( namespace , 'index' , true )
459463 this . debouncedPersistDocMap . delete ( namespace )
460464 this . debouncedPersistMap . delete ( namespace )
461465 } ,
0 commit comments