aboutsummaryrefslogtreecommitdiffstats
path: root/src/document
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-09 20:31:10 +0000
committertv <tv@krebsco.de>2026-11-09 22:21:15 +0100
commit67b5c3ae079f9f524bf0c52521a62811da407ad0 (patch)
treedb60596400fee35617d0fd3847987195efbb7ba0 /src/document
parent152890f321075beede075314d37ff6451604c359 (diff)
stats: the writers of the document
How many writers (Automerge actors) the document's changes have matters: a writer is a node's run (each start, rejoin or drop makes one, a start keeping the one of before with `--keep-actor` after a clean stop), and every transfer of the whole history carries a signature for each. `/admin/stats` now says it (`document.writers`, and `document_writers` for Prometheus), counted from the changes' metadata alongside the saved size's measurement in the background (at least a minute apart), as that takes time proportional to the document too; an export, which measures the size alone, keeps the count of before. The dashboard's figures show it with the rest.
Diffstat (limited to 'src/document')
-rw-r--r--src/document/mod.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/document/mod.rs b/src/document/mod.rs
index c183537..a546d63 100644
--- a/src/document/mod.rs
+++ b/src/document/mod.rs
@@ -13,6 +13,16 @@ pub(crate) use automerge::{
ScalarValue,
};
+/// How many writers (actors) `doc`'s changes have: from the changes' metadata, in
+/// time proportional to the document.
+pub(crate) fn writers(doc: &Document) -> usize {
+ doc.get_changes_meta(&[])
+ .into_iter()
+ .map(|meta| meta.actor.into_owned())
+ .collect::<std::collections::HashSet<_>>()
+ .len()
+}
+
/// The whole document as bytes, as the engine saves it: a backup, the document
/// file's full save, the size a joining node downloads.
pub(crate) fn save(doc: &Document) -> Vec<u8> {