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:404–444  ·  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

402 }
403
404 fn index_session_turn_candidate(
405 &mut self,
406 record: crate::change::session::SessionRecord,
407 existing_turns: Vec<crate::change::session::SessionTurn>,
408 mut candidate: crate::change::session::SessionTurn,
409 ) -> PristineResult<()> {
410 use crate::change::session::canonicalize_session_turns;
411
412 let current_schema = self.has_current_session_ledger_schema(&record.session_id)?;
413 candidate.turn_number = existing_turns.len() as u32;
414
415 // The common chained append cannot sort before an existing turn:
416 // causality keeps it blocked until the current last turn is emitted.
417 let chained_append = existing_turns.is_empty()
418 || candidate.previous_provenance
419 == existing_turns.last().map(|turn| turn.provenance_hash);
420 if current_schema && chained_append {
421 return self.append_session_turn(record, candidate, &existing_turns);
422 }
423
424 let mut all_turns = existing_turns.clone();
425 all_turns.push(candidate);
426 let canonical = canonicalize_session_turns(all_turns);
427
428 // Independent roots may also sort at the end. Keep the append-only
429 // write path when canonicalization leaves every prior row untouched.
430 if current_schema
431 && canonical.get(..existing_turns.len()) == Some(existing_turns.as_slice())
432 {
433 if let Some(last) = canonical.last() {
434 if !existing_turns
435 .iter()
436 .any(|turn| turn.provenance_hash == last.provenance_hash)
437 {
438 return self.append_session_turn(record, last.clone(), &existing_turns);
439 }
440 }
441 }
442
443 self.rewrite_session_turns(record, canonical)
444 }
445
446 /// Rewrite one session's derived index from its complete immutable turn
447 /// 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