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

Method append_session_turn

atomic-core/src/pristine/txn/write/mod.rs:363–401  ·  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

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