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

Method project_session_kg

atomic-core/src/pristine/txn/write/session_kg.rs:378–437  ·  view source on GitHub ↗
(
        &mut self,
        record: &SessionRecord,
        turns: &[SessionTurn],
    )

Source from the content-addressed store, hash-verified

376 }
377
378 pub fn project_session_kg(
379 &mut self,
380 record: &SessionRecord,
381 turns: &[SessionTurn],
382 ) -> PristineResult<()> {
383 if !self.kg_writes_enabled()? {
384 return Ok(());
385 }
386 self.emit_session_node(record)?;
387 let numbers: std::collections::HashMap<Hash, u32> = turns
388 .iter()
389 .map(|turn| (turn.provenance_hash, turn.turn_number))
390 .collect();
391 for turn in turns {
392 self.emit_turn_kg(
393 record,
394 turn,
395 turn.previous_provenance
396 .and_then(|hash| numbers.get(&hash).copied()),
397 )?;
398 }
399 let lineage = {
400 use crate::change::session::SessionManifest;
401 use crate::pristine::tables::{SESSION_HEADS, SESSION_MANIFESTS};
402 let heads = self.txn.open_table(SESSION_HEADS)?;
403 let manifests = self.txn.open_table(SESSION_MANIFESTS)?;
404 let decode = |bytes: &[u8]| {
405 SessionManifest::from_bytes(bytes).map_err(|error| PristineError::Serialization {
406 message: error.to_string(),
407 })
408 };
409 let mut lineage = None;
410 if let Some(head) = heads.get(record.session_id.as_str())? {
411 if let Some(bytes) = manifests.get(head.value())? {
412 let manifest = decode(bytes.value())?;
413 if let (Some(parent), Some(turn)) =
414 (manifest.parent_session, manifest.fork_turn)
415 {
416 if let Some(bytes) = manifests.get(parent.as_bytes())? {
417 lineage = Some((decode(bytes.value())?.session_id, turn, parent));
418 }
419 }
420 }
421 }
422 lineage
423 };
424 if let Some((parent, turn, manifest)) = lineage {
425 let parent_id = iri::mint_session(&self.kg_project()?, &parent);
426 if self.get_kg_node(&parent_id)?.is_none() {
427 self.upsert_kg_node(&KgNode::new(
428 parent_id,
429 Class::Session,
430 &parent,
431 "session_ledger",
432 ))?;
433 }
434 self.emit_session_fork_kg(&record.session_id, &parent, turn, &manifest)?;
435 }

Calls 15

kg_writes_enabledMethod · 0.80
emit_session_nodeMethod · 0.80
emit_turn_kgMethod · 0.80
valueMethod · 0.80
kg_projectMethod · 0.80
is_noneMethod · 0.80
upsert_kg_nodeMethod · 0.80
emit_session_fork_kgMethod · 0.80
getMethod · 0.65
decodeFunction · 0.50
collectMethod · 0.45
iterMethod · 0.45