aboutsummaryrefslogtreecommitdiffstats
path: root/src/remake/records.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
commit6105507200231e67ba544c12aa10b988e1c23826 (patch)
tree880530b7401cb5d43f52e06a68b4d704326aa272 /src/remake/records.rs
parent8d7adfbdb7798cca9d9783761f290e3bd85d9a3a (diff)
use Automerge as Document instead of AutoCommit
This allows a lot of operations to drop mut.
Diffstat (limited to 'src/remake/records.rs')
-rw-r--r--src/remake/records.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/remake/records.rs b/src/remake/records.rs
index fecae4c..55fa8a0 100644
--- a/src/remake/records.rs
+++ b/src/remake/records.rs
@@ -38,7 +38,7 @@ use crate::clock::UnixMillis;
use crate::document::meta::{self, REMAKES, VOTES};
use crate::document::replica::Epoch;
use crate::document::store::{self, StoreError};
-use crate::document::{ChangeHash, Document, Transactable};
+use crate::document::{ChangeHash, ReadDoc, Transactable};
/// One day, for retention defaults.
const DAY_MS: u64 = 24 * 60 * 60 * 1000;
@@ -337,13 +337,13 @@ pub(crate) fn record_path(id: &str, part: &str) -> Vec<String> {
}
/// The record with this ID, if it exists and is readable, with its votes.
-pub(crate) fn load(doc: &Document, id: &str) -> Option<Record> {
+pub(crate) fn load(doc: &impl ReadDoc, id: &str) -> Option<Record> {
let record = load_record(doc, id)?;
Some(with_votes(id, record, &load_register(doc)))
}
/// All readable records, with their votes.
-pub(crate) fn load_all(doc: &Document) -> Vec<(String, Record)> {
+pub(crate) fn load_all(doc: &impl ReadDoc) -> Vec<(String, Record)> {
let register = load_register(doc);
store::keys_at(doc, &records_dir())
.unwrap_or_default()
@@ -366,7 +366,7 @@ fn with_votes(id: &str, mut record: Record, register: &Register) -> Record {
record
}
-fn load_record(doc: &Document, id: &str) -> Option<Record> {
+fn load_record(doc: &impl ReadDoc, id: &str) -> Option<Record> {
let value = match store::read_path(doc, &record_path(id, "")) {
Ok(Some(value)) => value,
Ok(None) => return None,
@@ -390,7 +390,7 @@ fn load_record(doc: &Document, id: &str) -> Option<Record> {
}
/// A commit among concurrent decisions of remake `id` that disagree, if they do.
-fn contested_decision(doc: &Document, id: &str) -> Option<Decision> {
+fn contested_decision(doc: &impl ReadDoc, id: &str) -> Option<Decision> {
let decisions: Vec<Decision> = store::read_candidates(doc, &record_path(id, "decision"))
.ok()?
.into_iter()
@@ -418,7 +418,7 @@ fn register_path(voter: &str) -> Vec<String> {
}
/// The votes register; unreadable entries are skipped with a warning.
-pub(crate) fn load_register(doc: &Document) -> Register {
+pub(crate) fn load_register(doc: &impl ReadDoc) -> Register {
store::keys_at(doc, &meta::path(&[VOTES]))
.unwrap_or_default()
.into_iter()
@@ -503,6 +503,7 @@ pub(crate) fn decode_hex32(hex: &str) -> Option<[u8; 32]> {
#[cfg(test)]
mod tests {
use super::*;
+ use crate::document::Document;
use crate::document::testing::change;
#[test]