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

Method get_session_events

atomic-core/src/pristine/txn/read.rs:551–578  ·  view source on GitHub ↗

Get all session events for a provenance graph. Returns events in sequence order. Empty if the provenance is not Sherpa or has no session data.

(
        &self,
        provenance_id: u64,
    )

Source from the content-addressed store, hash-verified

549 /// Returns events in sequence order. Empty if the provenance is not Sherpa
550 /// or has no session data.
551 pub fn get_session_events(
552 &self,
553 provenance_id: u64,
554 ) -> PristineResult<Vec<crate::change::session::SessionEvent>> {
555 use crate::change::session::{encode_session_prefix, SessionEvent};
556
557 let table = self.txn.open_table(SESSION_EVENTS)?;
558 let mut events = Vec::new();
559
560 // Use a bounded prefix range instead of a full-table scan.
561 // All keys for `provenance_id` lie in [prefix(id), prefix(id+1)).
562 let start = encode_session_prefix(provenance_id);
563 let end = encode_session_prefix(provenance_id.saturating_add(1));
564 for result in table.range::<&[u8; 16]>(&start..&end)? {
565 let (_key, value) = result?;
566 match SessionEvent::from_bytes(value.value()) {
567 Ok(event) => events.push(event),
568 Err(e) => {
569 log::warn!("Failed to deserialize session event: {}", e);
570 }
571 }
572 }
573
574 // Events are already in seq order because keys encode (provenance_id,
575 // seq) with the same byte layout, but sort explicitly to be safe.
576 events.sort_by_key(|e| e.seq);
577 Ok(events)
578 }
579
580 /// Get all todos for a provenance graph.
581 ///

Callers

nothing calls this directly

Calls 2

encode_session_prefixFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected