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

Method import_sandbox_slice

atomic-repository/src/repository/remote_cache.rs:1201–1277  ·  view source on GitHub ↗

Cache side: replace graph rows and reconstruct canonical derived indexes. Hold the authenticated changes first, then import a slice covering every owner inode from [`Self::sandbox_slice_inodes`]. The complete closure is required for path/attribute projection; a thin content slice is insufficient.

(&self, slice: &SandboxSlice)

Source from the content-addressed store, hash-verified

1199 /// owner inode from [`Self::sandbox_slice_inodes`]. The complete closure is
1200 /// required for path/attribute projection; a thin content slice is insufficient.
1201 pub fn import_sandbox_slice(&self, slice: &SandboxSlice) -> Result<(), RepositoryError> {
1202 let view_id = {
1203 let txn = self.pristine.read_txn().map_err(db)?;
1204 txn.get_view(self.current_view())
1205 .map_err(db)?
1206 .ok_or_else(|| RepositoryError::ViewNotFound {
1207 name: self.current_view().to_string(),
1208 })?
1209 .id
1210 };
1211 let mut txn = self.pristine.write_txn().map_err(db)?;
1212 txn.import_graph_slice(&slice.rows, view_id).map_err(db)?;
1213 let view = txn
1214 .get_view(self.current_view())
1215 .map_err(db)?
1216 .ok_or_else(|| RepositoryError::ViewNotFound {
1217 name: self.current_view().into(),
1218 })?;
1219 // A just-submitted change may already have its file in the cache but
1220 // only receive its owner's node id in the new skeleton. Index all
1221 // canonical dependencies even when no change download was necessary.
1222 let mut pending = super::view_membership(&txn, &view)?
1223 .iter()
1224 .copied()
1225 .collect::<Vec<_>>();
1226 let mut indexed = std::collections::HashSet::new();
1227 while let Some(id) = pending.pop() {
1228 if id.is_root() || !indexed.insert(id) {
1229 continue;
1230 }
1231 let hash = txn.get_external(id).map_err(db)?.ok_or_else(|| {
1232 RepositoryError::Database(format!("missing change hash for {id}"))
1233 })?;
1234 let change = self.load_change(&hash)?;
1235 for hash in change.dependencies() {
1236 pending.push(txn.get_internal(hash).map_err(db)?.ok_or_else(|| {
1237 RepositoryError::Database(format!("missing dependency {hash}"))
1238 })?);
1239 }
1240 txn.put_change_deps(id, change.dependencies()).map_err(db)?;
1241 }
1242 let closure = super::graph_visibility_closure(&txn, &view)?;
1243 let mut claims = Vec::new();
1244 // Reconstruct derived indexes from authenticated canonical changes and
1245 // imported graph identities. TREE is never used as file history.
1246 for id in closure
1247 .iter_dependency_first()
1248 .copied()
1249 .filter(|id| !id.is_root())
1250 {
1251 let hash = txn.get_external(id).map_err(db)?.ok_or_else(|| {
1252 RepositoryError::Database(format!("missing change hash for {id}"))
1253 })?;
1254 let change = self.load_change(&hash)?;
1255 claims.extend(
1256 super::name_resolution::path_claim_events_for_change_with_prior(
1257 &txn, id, &change, &claims,
1258 )?,

Callers 3

hydrate_cacheFunction · 0.80

Calls 15

view_membershipFunction · 0.85
graph_visibility_closureFunction · 0.85
apply_set_attrFunction · 0.85
read_txnMethod · 0.80
write_txnMethod · 0.80
import_graph_sliceMethod · 0.80
put_change_depsMethod · 0.80
iter_dependency_firstMethod · 0.80
extendMethod · 0.80
put_path_claimMethod · 0.80

Tested by 2

hydrate_cacheFunction · 0.64