From 6105507200231e67ba544c12aa10b988e1c23826 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 19:53:27 +0100 Subject: use Automerge as Document instead of AutoCommit This allows a lot of operations to drop mut. --- src/swarm/changes.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/swarm/changes.rs') diff --git a/src/swarm/changes.rs b/src/swarm/changes.rs index 3a50769..7f3c2e9 100644 --- a/src/swarm/changes.rs +++ b/src/swarm/changes.rs @@ -21,9 +21,8 @@ pub(crate) async fn run_change_publisher(state: AppState) { let before = last_heads.clone(); let doc = Arc::clone(&state.doc); - // Looking changes up needs the document mutably. let (heads, paths, conflicts) = tokio::task::spawn_blocking(move || { - let mut replica = doc.blocking_write(); + let replica = doc.blocking_read(); let heads = replica.heads().to_vec(); if heads == before { return (heads, Vec::new(), Vec::new()); @@ -31,13 +30,13 @@ pub(crate) async fn run_change_publisher(state: AppState) { // After an epoch switch the previous heads belong to the old document: // report the root as changed, which every stream is related to. - if !changes::missing(&mut replica.doc, &before).is_empty() { + if !changes::missing(&replica.doc, &before).is_empty() { return (heads, vec![Vec::new()], Vec::new()); } let mut paths = Vec::new(); let mut conflicts = Vec::new(); - for changed in store::changed(&mut replica.doc, &before, &heads, InLists::Index) { + for changed in store::changed(&replica.doc, &before, &heads, InLists::Index) { if changed.conflict { conflicts.push(changed.path.clone()); } -- cgit v1.3.1