diff options
| author | tv <tv@krebsco.de> | 2026-11-01 23:09:28 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-01 23:09:28 +0100 |
| commit | a73676c722fa462d373729af34938baeefa5c802 (patch) | |
| tree | d2f8aa048c8badb850f176436d33a094e18ec18d /src/state | |
| parent | 7ca6a00cd3581e00686682af9010587028170cd5 (diff) | |
api: add x-continuum-heads to writes
Diffstat (limited to 'src/state')
| -rw-r--r-- | src/state/mod.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/state/mod.rs b/src/state/mod.rs index 85955fe..aebc59a 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -418,16 +418,17 @@ impl AppState { T: Send + 'static, E: From<StoreError> + Send + 'static, { - self.mutate_doc_for(None, f).await + self.mutate_doc_for(None, f).await.map(|(out, _)| out) } /// [`mutate_doc`](Self::mutate_doc) for `user`, who wrote through the API: the - /// change names them (`replica::Writer`). + /// change names them (`replica::Writer`). With the heads of the document written to + /// after the write (sorted): what a read must have to include it. pub(crate) async fn mutate_doc_for<T, E>( &self, user: Option<String>, f: impl FnOnce(&mut Transaction<'_>) -> Result<T, E> + Send + 'static, - ) -> Result<T, E> + ) -> Result<(T, Vec<crate::document::ChangeHash>), E> where T: Send + 'static, E: From<StoreError> + Send + 'static, @@ -451,12 +452,15 @@ impl AppState { node: state.local_id(), user: user.as_deref(), }; - return crate::document::replica::transact( + let out = crate::document::replica::transact( &mut doc, state.clock.now_millis(), &writer, f, - ); + )?; + let mut heads = doc.get_heads(); + heads.sort_unstable(); + return Ok((out, heads)); } // One API write = one change; on error, its partial writes (e.g. the old // value deleted, the new one not written) are dropped. @@ -466,7 +470,7 @@ impl AppState { }; let result = replica.transact(state.clock.now_millis(), &writer, f); replica.refresh_heads(); - result + result.map(|out| (out, replica.heads().to_vec())) }; // lock released before notifying if result.is_ok() { |
