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

Method export_sandbox_slice

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

Serve side: what `record` on `view` reads for `inodes`, with the content of every vertex a visible change introduced.

(
        &self,
        view: &str,
        inodes: &[u64],
    )

Source from the content-addressed store, hash-verified

496 /// Serve side: what `record` on `view` reads for `inodes`, with the
497 /// content of every vertex a visible change introduced.
498 pub fn export_sandbox_slice(
499 &self,
500 view: &str,
501 inodes: &[u64],
502 ) -> Result<SandboxSlice, RepositoryError> {
503 let txn = self.pristine.read_txn().map_err(db)?;
504 let state =
505 txn.get_view(view)
506 .map_err(db)?
507 .ok_or_else(|| RepositoryError::ViewNotFound {
508 name: view.to_string(),
509 })?;
510 let visible: BTreeSet<u64> = self.sandbox_visible(&txn, &state)?.into_iter().collect();
511 // Only files the view has: an inode another view introduced is not
512 // this sandbox's to read.
513 let mut on_view = Vec::with_capacity(inodes.len());
514 for &inode in inodes {
515 let position = txn
516 .inode_position(atomic_core::types::Inode::new(inode))
517 .map_err(db)?;
518 if position.is_some_and(|p| p.change.is_root() || visible.contains(&p.change.get())) {
519 on_view.push(inode);
520 }
521 }
522 let rows = txn
523 .export_graph_slice(&on_view, state.id, &visible)
524 .map_err(db)?;
525 let mut spans = Vec::new();
526 for (key, _) in &rows.graph {
527 let (change, start, end) = decode_vertex(key);
528 if start >= end || !visible.contains(&change) {
529 continue;
530 }
531 let Some(hash) = txn.get_external(NodeId::new(change)).map_err(db)? else {
532 continue;
533 };
534 let node = GraphNode {
535 change: NodeId::new(change),
536 start: atomic_core::types::ChangePosition::new(start),
537 end: atomic_core::types::ChangePosition::new(end),
538 };
539 let mut bytes = vec![0u8; (end - start) as usize];
540 self.change_store
541 .get_contents(|_| Some(hash), node, &mut bytes)
542 .map_err(db)?;
543 spans.push(SpanBytes {
544 change: hash,
545 start,
546 bytes,
547 });
548 }
549 Ok(SandboxSlice { rows, spans })
550 }
551
552 /// Serve side: the view's skeleton as it is right now, with nothing of it
553 /// applied. What a sandbox needs after being told its base state is stale:

Callers 3

hydrate_cacheFunction · 0.80
get_file_statesMethod · 0.80

Calls 15

decode_vertexFunction · 0.85
read_txnMethod · 0.80
sandbox_visibleMethod · 0.80
export_graph_sliceMethod · 0.80
getMethod · 0.65
get_viewMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
lenMethod · 0.45
inode_positionMethod · 0.45
is_rootMethod · 0.45
containsMethod · 0.45

Tested by 2

hydrate_cacheFunction · 0.64