MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / view_scopes

Function view_scopes

atomic-repository/src/workflow_usage.rs:27–90  ·  view source on GitHub ↗

Capture authoritative view filters in the same read transaction as KG rows. KG membership edges can lag record/insert operations and are not accounting authority for effective view membership.

(
    repo: &Repository,
    txn: &impl atomic_core::pristine::ViewTxnT,
    project: &atomic_core::kg::project_id::ProjectId,
)

Source from the content-addressed store, hash-verified

25/// KG membership edges can lag record/insert operations and are not accounting
26/// authority for effective view membership.
27pub(crate) fn view_scopes(
28 repo: &Repository,
29 txn: &impl atomic_core::pristine::ViewTxnT,
30 project: &atomic_core::kg::project_id::ProjectId,
31) -> Result<BTreeMap<String, ViewUsageScope>, RepositoryError> {
32 let mut scopes = BTreeMap::new();
33 let mut dependency_cache = BTreeMap::<Hash, Vec<Hash>>::new();
34 for name in txn.list_views()? {
35 let Some(view) = txn.get_view(&name)? else {
36 continue;
37 };
38 let mut scope = ViewUsageScope {
39 changes: BTreeSet::new(),
40 error: None,
41 };
42 // Accounting does not traverse the byte graph. Resolve canonical view
43 // membership, then verify dependency headers directly rather than
44 // requiring old repositories to backfill a traversal acceleration index.
45 match crate::repository::view_membership(txn, &view) {
46 Ok(membership) => {
47 let mut pending = Vec::new();
48 for change in membership.iter() {
49 if let Some(hash) = txn.get_external(*change)? {
50 pending.push(hash);
51 } else {
52 scope.error =
53 Some("A canonical view member has no external change hash".into());
54 }
55 }
56 while let Some(hash) = pending.pop() {
57 if !scope.changes.insert(iri::mint_change(&hash)) {
58 continue;
59 }
60 if let std::collections::btree_map::Entry::Vacant(entry) =
61 dependency_cache.entry(hash)
62 {
63 match repo.load_change(&hash) {
64 Ok(change) => {
65 entry.insert(change.dependencies().to_vec());
66 }
67 Err(RepositoryError::ChangeNotFound { .. }) => {
68 scope.error = Some(format!("View change {} is unavailable; dependency closure may be incomplete", hash.to_base32()));
69 continue;
70 }
71 Err(error) => return Err(error),
72 }
73 }
74 for dependency in &dependency_cache[&hash] {
75 if txn.get_internal(dependency)?.is_none() {
76 scope.error = Some(format!(
77 "View dependency {} is not registered in the canonical graph",
78 dependency.to_base32()
79 ));
80 }
81 pending.push(*dependency);
82 }
83 }
84 }

Callers 1

workflow_snapshotMethod · 0.85

Calls 11

view_membershipFunction · 0.85
is_noneMethod · 0.80
list_viewsMethod · 0.45
get_viewMethod · 0.45
iterMethod · 0.45
get_externalMethod · 0.45
pushMethod · 0.45
insertMethod · 0.45
load_changeMethod · 0.45
dependenciesMethod · 0.45
get_internalMethod · 0.45

Tested by

no test coverage detected