@@ -300,6 +300,8 @@ module.exports = class SessionState {
300300 const append = b ? { start : b . start , length : b . appends , drop : false } : null
301301
302302 this . onappend ( tree , append , true )
303+
304+ if ( this . core . hintsChanged && this . isDefault ( ) ) await this . core . flushHints ( )
303305 } finally {
304306 this . mutex . unlock ( )
305307 this . core . checkIfIdle ( )
@@ -360,6 +362,8 @@ module.exports = class SessionState {
360362
361363 this . onappend ( head , bitfield , flushed )
362364 }
365+
366+ if ( this . core . hintsChanged && this . isDefault ( ) ) await this . core . flushHints ( )
363367 } finally {
364368 this . _clearActiveBatch ( )
365369 this . updating = false
@@ -419,6 +423,8 @@ module.exports = class SessionState {
419423 if ( dependency ) this . storage . setDependencyHead ( dependency )
420424
421425 this . ontruncate ( tree , tree . length , batch . treeLength , flushed )
426+
427+ if ( this . core . hintsChanged && this . isDefault ( ) ) await this . core . flushHints ( )
422428 } finally {
423429 this . _unlock ( )
424430 }
@@ -445,6 +451,8 @@ module.exports = class SessionState {
445451 if ( dependency ) this . storage . setDependencyHead ( dependency )
446452
447453 this . ontruncate ( tree , batch . ancestors , batch . treeLength , flushed )
454+
455+ if ( this . core . hintsChanged && this . isDefault ( ) ) await this . core . flushHints ( )
448456 } finally {
449457 this . _unlock ( )
450458 }
@@ -487,23 +495,6 @@ module.exports = class SessionState {
487495 return { dependency, tree, roots : batch . roots }
488496 }
489497
490- async flushHints ( ) {
491- await this . mutex . lock ( )
492-
493- try {
494- const tx = this . createWriteBatch ( )
495-
496- tx . setHints ( {
497- contiguousLength : this . core . header . hints . contiguousLength ,
498- remoteContiguousLength : this . core . header . hints . remoteContiguousLength
499- } )
500-
501- await tx . flush ( )
502- } finally {
503- this . _unlock ( )
504- }
505- }
506-
507498 async clear ( start , end , cleared ) {
508499 await this . mutex . lock ( )
509500
@@ -548,9 +539,12 @@ module.exports = class SessionState {
548539 // todo: atomic event handle
549540 if ( this . isDefault ( ) && flushed ) {
550541 const length = end - start
542+
551543 this . core . updateContiguousLength ( { start, length, drop : true } )
552544 this . core . _setBitfieldRanges ( start , end , false )
553545 this . core . replicator . onhave ( start , length , true )
546+
547+ if ( this . core . hintsChanged ) await this . core . flushHints ( )
554548 }
555549 } finally {
556550 this . _unlock ( )
@@ -631,6 +625,8 @@ module.exports = class SessionState {
631625
632626 this . onappend ( tree , bitfield , flushed )
633627
628+ if ( this . core . hintsChanged && this . isDefault ( ) ) await this . core . flushHints ( )
629+
634630 return { length : this . length , byteLength : this . byteLength }
635631 } finally {
636632 this . _unlock ( )
@@ -780,6 +776,8 @@ module.exports = class SessionState {
780776
781777 if ( truncating ) this . ontruncate ( tree , sharedLength , origLength , flushed )
782778 if ( sharedLength < length ) this . onappend ( tree , null , flushed )
779+
780+ if ( this . core . hintsChanged && this . isDefault ( ) ) await this . core . flushHints ( )
783781 } finally {
784782 this . mutex . unlock ( )
785783 }
0 commit comments