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