From b2273bc74e18201318f1e86b0f27a6a3cd874629 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 22:22:41 +0100 Subject: record node ID and API user for every write --- src/state/mod.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/state/mod.rs') diff --git a/src/state/mod.rs b/src/state/mod.rs index cd96aaf..85955fe 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -414,6 +414,20 @@ impl AppState { &self, f: impl FnOnce(&mut Transaction<'_>) -> Result + Send + 'static, ) -> Result + where + T: Send + 'static, + E: From + Send + 'static, + { + self.mutate_doc_for(None, f).await + } + + /// [`mutate_doc`](Self::mutate_doc) for `user`, who wrote through the API: the + /// change names them (`replica::Writer`). + pub(crate) async fn mutate_doc_for( + &self, + user: Option, + f: impl FnOnce(&mut Transaction<'_>) -> Result + Send + 'static, + ) -> Result where T: Send + 'static, E: From + Send + 'static, @@ -433,15 +447,24 @@ impl AppState { return Err(E::from(StoreError::Rejoining)); }; let mut doc = stale.write_or_recover(); + let writer = crate::document::replica::Writer { + node: state.local_id(), + user: user.as_deref(), + }; return crate::document::replica::transact( &mut doc, state.clock.now_millis(), + &writer, f, ); } // One API write = one change; on error, its partial writes (e.g. the old // value deleted, the new one not written) are dropped. - let result = replica.transact(state.clock.now_millis(), f); + let writer = crate::document::replica::Writer { + node: state.local_id(), + user: user.as_deref(), + }; + let result = replica.transact(state.clock.now_millis(), &writer, f); replica.refresh_heads(); result }; // lock released before notifying -- cgit v1.3.1