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

Method append_session_turn

atomic-core/src/pristine/txn/write/mod.rs:364–402  ·  view source on GitHub ↗

Append a turn without touching prior rows when the existing session was already written with the current canonical schema.

(
        &mut self,
        mut record: crate::change::session::SessionRecord,
        turn: crate::change::session::SessionTurn,
        existing_turns: &[crate::change::session::SessionTurn],
    )

Source from the content-addressed store, hash-verified

362 /// Append a turn without touching prior rows when the existing session was
363 /// already written with the current canonical schema.
364 fn append_session_turn(
365 &mut self,
366 mut record: crate::change::session::SessionRecord,
367 turn: crate::change::session::SessionTurn,
368 existing_turns: &[crate::change::session::SessionTurn],
369 ) -> PristineResult<()> {
370 use crate::change::session::{encode_session_turn_key, session_turn_namespace};
371
372 let key =
373 encode_session_turn_key(session_turn_namespace(&record.session_id), turn.turn_number);
374 {
375 let mut turns = self.txn.open_table(SESSION_TURNS)?;
376 let mut reverse = self.txn.open_table(SESSION_PROVENANCE)?;
377 let bytes = turn.to_bytes();
378 turns.insert(&key, bytes.as_slice())?;
379 reverse.insert(turn.provenance_hash.as_bytes(), &key)?;
380 }
381
382 if record.first_provenance.is_none() {
383 record.first_provenance = Some(turn.provenance_hash);
384 }
385 record.latest_provenance = Some(turn.provenance_hash);
386 record.turn_count = turn.turn_number.saturating_add(1);
387 record.started_at = record.started_at.min(turn.timestamp);
388 {
389 let mut sessions = self.txn.open_table(SESSIONS)?;
390 let bytes = record.to_bytes();
391 sessions.insert(record.session_id.as_str(), bytes.as_slice())?;
392 }
393
394 let previous_turn_number = turn.previous_provenance.and_then(|hash| {
395 existing_turns
396 .iter()
397 .find(|existing| existing.provenance_hash == hash)
398 .map(|existing| existing.turn_number)
399 .or_else(|| (hash == turn.provenance_hash).then_some(turn.turn_number))
400 });
401 self.emit_turn_kg(&record, &turn, previous_turn_number)
402 }
403
404 fn index_session_turn_candidate(
405 &mut self,

Callers 1

Calls 10

encode_session_turn_keyFunction · 0.85
session_turn_namespaceFunction · 0.85
is_noneMethod · 0.80
emit_turn_kgMethod · 0.80
to_bytesMethod · 0.45
insertMethod · 0.45
as_sliceMethod · 0.45
as_bytesMethod · 0.45
as_strMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected