@@ -18,11 +18,11 @@ const logSocketIO = createModuleLogger('@y/socket-io/server')
18
18
const PERSIST_INTERVAL = number . parseInt ( env . getConf ( 'y-socket-io-server-persist-interval' ) || '3000' )
19
19
const REVALIDATE_TIMEOUT = number . parseInt ( env . getConf ( 'y-socket-io-server-revalidate-timeout' ) || '60000' )
20
20
21
- process . on ( 'SIGINT' , function ( ) {
21
+ process . on ( 'SIGINT' , function ( ) {
22
22
// calling .shutdown allows your process to exit normally
23
- toobusy . shutdown ( ) ;
24
- process . exit ( ) ;
25
- } ) ;
23
+ toobusy . shutdown ( )
24
+ process . exit ( )
25
+ } )
26
26
27
27
/**
28
28
* @typedef {import('socket.io').Namespace } Namespace
@@ -411,8 +411,12 @@ export class YSocketIO {
411
411
changed = tr . changed . size > 0
412
412
} )
413
413
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
+ }
415
418
for ( const msg of awareness ) {
419
+ if ( msg . length === 0 ) continue
416
420
AwarenessProtocol . applyAwarenessUpdate ( existDoc . awareness , msg , null )
417
421
}
418
422
} )
@@ -426,10 +430,9 @@ export class YSocketIO {
426
430
changed = getDoc . changed
427
431
}
428
432
assert ( doc )
429
- this . debouncedPersist ( namespace , doc . ydoc )
433
+ if ( changed ) this . debouncedPersist ( namespace , doc . ydoc )
430
434
this . namespaceDocMap . get ( namespace ) ?. ydoc . destroy ( )
431
435
this . namespaceDocMap . set ( namespace , doc )
432
- await this . client . trimRoomStream ( namespace , 'index' , nsp . sockets . size === 0 )
433
436
}
434
437
435
438
/**
@@ -456,6 +459,7 @@ export class YSocketIO {
456
459
const doc = this . debouncedPersistDocMap . get ( namespace )
457
460
if ( ! doc ) return
458
461
await this . client . store . persistDoc ( namespace , 'index' , doc )
462
+ await this . client . trimRoomStream ( namespace , 'index' , true )
459
463
this . debouncedPersistDocMap . delete ( namespace )
460
464
this . debouncedPersistMap . delete ( namespace )
461
465
} ,
0 commit comments