File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
packages/common/infra/src/sync/doc Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -142,17 +142,22 @@ export class DocEngine {
142142 }
143143
144144 addDoc ( doc : YDoc , withSubDocs = true ) {
145- this . localPart . actions . addDoc ( doc ) ;
146145 this . remotePart ?. actions . addDoc ( doc . guid ) ;
146+ this . localPart . actions . addDoc ( doc ) ;
147147
148148 if ( withSubDocs ) {
149- const subdocs = doc . getSubdocs ( ) ;
150- for ( const subdoc of subdocs ) {
151- this . addDoc ( subdoc , false ) ;
152- }
153- doc . on ( 'subdocs' , ( { added } : { added : Set < YDoc > } ) => {
149+ doc . on ( 'subdocs' , ( { added, loaded } ) => {
150+ // added: the subdocs that are existing on the ydoc
151+ // loaded: the subdocs that have been called `ydoc.load()`
152+ //
153+ // we add all existing subdocs to remote part, let them sync between storage and server
154+ // but only add loaded subdocs to local part, let them sync between storage and ydoc
155+ // sync data to ydoc will consume more memory, so we only sync the ydoc that are necessary.
154156 for ( const subdoc of added ) {
155- this . addDoc ( subdoc , false ) ;
157+ this . remotePart ?. actions . addDoc ( subdoc . guid ) ;
158+ }
159+ for ( const subdoc of loaded ) {
160+ this . localPart . actions . addDoc ( subdoc ) ;
156161 }
157162 } ) ;
158163 }
You can’t perform that action at this time.
0 commit comments