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

Method index_session_turn_candidate

atomic-core/src/pristine/txn/write/mod.rs:499–539  ·  view source on GitHub ↗
(
        &mut self,
        record: crate::change::session::SessionRecord,
        existing_turns: Vec<crate::change::session::SessionTurn>,
        mut candidate: crate::change::session::SessionTurn

Source from the content-addressed store, hash-verified

497 }
498
499 fn index_session_turn_candidate(
500 &mut self,
501 record: crate::change::session::SessionRecord,
502 existing_turns: Vec<crate::change::session::SessionTurn>,
503 mut candidate: crate::change::session::SessionTurn,
504 ) -> PristineResult<()> {
505 use crate::change::session::canonicalize_session_turns;
506
507 let current_schema = self.has_current_session_ledger_schema(&record.session_id)?;
508 candidate.turn_number = existing_turns.len() as u32;
509
510 // The common chained append cannot sort before an existing turn:
511 // causality keeps it blocked until the current last turn is emitted.
512 let chained_append = existing_turns.is_empty()
513 || candidate.previous_provenance
514 == existing_turns.last().map(|turn| turn.provenance_hash);
515 if current_schema && chained_append {
516 return self.append_session_turn(record, candidate, &existing_turns);
517 }
518
519 let mut all_turns = existing_turns.clone();
520 all_turns.push(candidate);
521 let canonical = canonicalize_session_turns(all_turns);
522
523 // Independent roots may also sort at the end. Keep the append-only
524 // write path when canonicalization leaves every prior row untouched.
525 if current_schema
526 && canonical.get(..existing_turns.len()) == Some(existing_turns.as_slice())
527 {
528 if let Some(last) = canonical.last() {
529 if !existing_turns
530 .iter()
531 .any(|turn| turn.provenance_hash == last.provenance_hash)
532 {
533 return self.append_session_turn(record, last.clone(), &existing_turns);
534 }
535 }
536 }
537
538 self.rewrite_session_turns(record, canonical)
539 }
540
541 /// Rewrite one session's derived index from its complete immutable turn
542 /// set. This keeps local keys, manifest order, lifecycle pointers, and KG

Callers 2

index_session_turnMethod · 0.80
index_inherited_turnMethod · 0.80

Calls 12

lastMethod · 0.80
append_session_turnMethod · 0.80
rewrite_session_turnsMethod · 0.80
getMethod · 0.65
lenMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45
as_sliceMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected