From c761bcfd03aafe1398109d657066a2498f62af33 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 15 Nov 2026 18:53:46 +0000 Subject: rules: the document's own policy read once for its heads Every change judged under a policy that isn't strict, in every swarm, read the document's own policy to ask whether the time before a strict policy applies: in a swarm without a policy, where a change was judged for nearly nothing, a read of the policy for each. It is now read once for the document's heads and kept while the batch is judged at others (`Reads::strict_now`), read again once the document takes more. --- src/access/rules.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/access/rules.rs b/src/access/rules.rs index 43404cf..745dd7e 100644 --- a/src/access/rules.rs +++ b/src/access/rules.rs @@ -95,6 +95,9 @@ pub(crate) struct Reads { member: HashMap, /// By user: what the registry lets it do. caps: HashMap, + /// Whether the document's own policy, at its heads then, is strict + /// (`before_strict`): kept across `seen`, read again once the document takes more. + strict_now: Option<(Vec, bool)>, } impl Reads { @@ -103,11 +106,25 @@ impl Reads { if self.seen != seen { *self = Self { seen: seen.to_vec(), + strict_now: self.strict_now.take(), ..Self::default() }; } self } + + /// Whether `doc`'s policy, as it stands, is strict: read once for its heads. + fn strict_now(&mut self, doc: &Document) -> bool { + let heads = doc.get_heads(); + match &self.strict_now { + Some((at, strict)) if *at == heads => *strict, + _ => { + let strict = super::policy::of(doc).strict(); + self.strict_now = Some((heads, strict)); + strict + } + } + } } impl Reads { @@ -161,6 +178,7 @@ pub(crate) fn judge_reading( .get_or_insert_with(|| super::policy::of(&at)) .clone(); if !policy.strict() + && reads.strict_now(doc) && let Some(why) = before_strict(doc, change) { return Err(Refusal::Rule(why)); @@ -359,11 +377,8 @@ pub(crate) fn judge_reading( /// later, strict over strict, names the same change; one written beside it, strict or /// not, is refused like any other, so a change made later to look as old can't take its /// place. A swarm strict from its genesis change (`--bootstrap-policy`) has no such -/// time. None where `doc`'s policy isn't strict: there, nothing changes. +/// time. Asked only where `doc`'s policy is strict: elsewhere, nothing changes. fn before_strict(doc: &Document, change: &Change<'_>) -> Option { - if !super::policy::of(doc).strict() { - return None; - } let held = crate::document::changes::holds(doc, &change.hash); let beside = turned_strict(doc).into_iter().find(|turned| { *turned != change.hash -- cgit v1.3.1