aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/sync.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 19:53:27 +0100
committertv <tv@krebsco.de>2026-10-31 19:53:27 +0100
commit9c12bf2e8815dc9b42be62f1e1fd2932dd02938b (patch)
tree09cd985fae9142a247a2285c755f9d002a2c7b30 /src/swarm/sync.rs
parentf4b0a7c5159d418e22682d2bd7d413fb3587ca7f (diff)
use Automerge as Document instead of AutoCommit
This allows a lot of operations to drop mut.
Diffstat (limited to 'src/swarm/sync.rs')
-rw-r--r--src/swarm/sync.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index 35bc4c7..46bdef6 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -136,7 +136,7 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> {
// Label the message with the epoch of the document it was generated
// from, read under the same lock.
let (session, epoch, epoch_seq, body) = {
- let mut replica = doc.blocking_write();
+ let replica = doc.blocking_read();
let mut peer_state = psm.blocking_lock();
let (epoch, epoch_seq) = (replica.epoch, replica.epoch_seq);
// Under the same locks as the epoch label: the message belongs to
@@ -144,7 +144,7 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> {
let message =
peer_state
.sync
- .generate(&mut replica.doc, Instant::now(), bytes_before);
+ .generate(&replica.doc, Instant::now(), bytes_before);
let body = message.map(|payload| {
if payload.0.len() <= delta_threshold {
return transport::SyncBody::Message(payload);
@@ -390,7 +390,7 @@ pub(crate) async fn handle_sync(
// doesn't count; the writer's still does.
let now_ms = clock.now_millis().as_u64() as i64 - ahead_ms;
let delays: Vec<i64> =
- crate::document::changes::commit_times(&mut replica.doc, &heads_before)
+ crate::document::changes::commit_times(&replica.doc, &heads_before)
.into_iter()
.map(|time| now_ms - time)
.collect();
@@ -403,7 +403,7 @@ pub(crate) async fn handle_sync(
// catching up has them, and so does a ready peer whose document is empty
// (a misconfigured second swarm, or a genesis node in its first seconds,
// before it registered itself).
- check_caught_up && from_ready && peer_state.sync.have_all_theirs(&mut replica.doc),
+ check_caught_up && from_ready && peer_state.sync.have_all_theirs(&replica.doc),
changed,
)))
})
@@ -501,7 +501,7 @@ async fn download_and_apply_delta(
let heads_before = replica.heads().to_vec();
crate::document::changes::load_delta(&mut replica.doc, &bytes)?;
replica.refresh_heads();
- let missing = crate::document::changes::missing(&mut replica.doc, &spec.to).len();
+ let missing = crate::document::changes::missing(&replica.doc, &spec.to).len();
if missing > 0 {
bail!("{missing} of the offered heads are still missing after loading");
}