aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 13:26:25 +0100
committertv <tv@krebsco.de>2026-10-31 13:26:25 +0100
commit0c5e612550e399c3aad458d5c1d70e5cc4267a15 (patch)
treeacd8b3a08da2fd256702af6b70e41d6b1ebaaad7 /src
parent694347ad456766004e2792c4b4cda865a8a40386 (diff)
commits go through the replica
Diffstat (limited to 'src')
-rw-r--r--src/document/replica.rs13
-rw-r--r--src/state/mod.rs17
2 files changed, 17 insertions, 13 deletions
diff --git a/src/document/replica.rs b/src/document/replica.rs
index 8640c7e..5d3d7a7 100644
--- a/src/document/replica.rs
+++ b/src/document/replica.rs
@@ -167,6 +167,19 @@ impl Replica {
pub(crate) fn stamps(&self) -> watch::Receiver<Stamp> {
self.stamp.subscribe()
}
+
+ /// The writes since the last commit, as one change stamped `at`: receivers tell by
+ /// it how long the change took to reach them (`swarm::stats`).
+ pub(crate) fn commit(&mut self, at: crate::clock::UnixMillis) {
+ self.doc.commit_with(
+ automerge::transaction::CommitOptions::default().with_time(at.as_u64() as i64),
+ );
+ }
+
+ /// The writes since the last commit, discarded.
+ pub(crate) fn rollback(&mut self) {
+ self.doc.rollback();
+ }
}
impl Deref for Replica {
diff --git a/src/state/mod.rs b/src/state/mod.rs
index efa4953..cf64dc3 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -413,7 +413,7 @@ impl AppState {
.expect("document write task panicked")
}
- /// Mutates the document on the blocking pool as one Automerge change, then
+ /// Mutates the document on the blocking pool as one change, then
/// publishes it. Write and notification run in the same blocking task, so a
/// cancelled request can't leave a committed write unannounced.
pub(crate) async fn mutate_doc<T, E>(
@@ -431,19 +431,10 @@ impl AppState {
let mut replica = state.doc.blocking_write();
let result = f(&mut replica.doc);
match &result {
- // One API write = one Automerge change.
- Ok(_) => {
- // Stamped with our clock (milliseconds), so receivers can tell
- // how long the change took to reach them (`swarm::stats`).
- replica.doc.commit_with(
- automerge::transaction::CommitOptions::default()
- .with_time(state.clock.now_millis().as_u64() as i64),
- );
- }
+ // One API write = one change.
+ Ok(_) => replica.commit(state.clock.now_millis()),
// Discard partial ops (e.g. old value deleted, new one not written).
- Err(_) => {
- replica.doc.rollback();
- }
+ Err(_) => replica.rollback(),
}
replica.refresh_heads();
result