@@ -721,6 +721,12 @@ impl DocumentInfo {
721
721
let count = {
722
722
let doc = self . document . read ( ) ;
723
723
let changes = doc. automerge . get_changes ( & self . last_heads ) ;
724
+ tracing:: trace!(
725
+ "last: {:?}, current: {:?}" ,
726
+ self . last_heads,
727
+ doc. automerge. get_heads( )
728
+ ) ;
729
+ //self.last_heads = doc.automerge.get_heads();
724
730
changes. len ( )
725
731
} ;
726
732
let has_patches = count > 0 ;
@@ -1245,16 +1251,16 @@ impl Repo {
1245
1251
// Handle doc changes: sync the document.
1246
1252
let local_repo_id = self . get_repo_id ( ) . clone ( ) ;
1247
1253
if let Some ( info) = self . documents . get_mut ( & doc_id) {
1248
- if !info. note_changes ( ) {
1249
- println ! ( "Doc didn't change" ) ;
1250
- // Stop here if the document wasn't actually changed.
1251
- return ;
1254
+ // only run the documents_with_changes workflow if there
1255
+ // was a change, but always generate potential sync messages
1256
+ // (below)
1257
+ if info. note_changes ( ) {
1258
+ self . documents_with_changes . push ( doc_id. clone ( ) ) ;
1252
1259
}
1253
1260
let is_first_edit = matches ! ( info. state, DocState :: LocallyCreatedNotEdited ) ;
1254
1261
if is_first_edit {
1255
1262
info. state = DocState :: Sync ( vec ! [ ] ) ;
1256
1263
}
1257
- self . documents_with_changes . push ( doc_id. clone ( ) ) ;
1258
1264
for ( to_repo_id, message) in info. generate_sync_messages ( ) . into_iter ( ) {
1259
1265
let outgoing = NetworkMessage :: Sync {
1260
1266
from_repo_id : local_repo_id. clone ( ) ,
@@ -1356,13 +1362,18 @@ impl Repo {
1356
1362
& self . repo_id ,
1357
1363
) ;
1358
1364
}
1359
- RepoEvent :: AddChangeObserver ( doc_id, change_hash , mut observer) => {
1365
+ RepoEvent :: AddChangeObserver ( doc_id, last_heads , mut observer) => {
1360
1366
if let Some ( info) = self . documents . get_mut ( & doc_id) {
1361
1367
let current_heads = {
1362
1368
let state = info. document . read ( ) ;
1363
1369
state. automerge . get_heads ( )
1364
1370
} ;
1365
- if current_heads == change_hash {
1371
+ tracing:: trace!(
1372
+ ?current_heads,
1373
+ ?last_heads,
1374
+ "handling AddChangeObserver event"
1375
+ ) ;
1376
+ if current_heads == last_heads {
1366
1377
info. change_observers . push ( observer) ;
1367
1378
} else {
1368
1379
// Resolve now if the document hash already changed.
@@ -1472,8 +1483,7 @@ impl Repo {
1472
1483
. get_mut ( & document_id)
1473
1484
. expect ( "Doc should have an info by now." ) ;
1474
1485
1475
- if info. receive_sync_message ( per_remote) {
1476
- info. note_changes ( ) ;
1486
+ if info. receive_sync_message ( per_remote) && info. note_changes ( ) {
1477
1487
self . documents_with_changes . push ( document_id. clone ( ) ) ;
1478
1488
}
1479
1489
0 commit comments