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

Method list_session_ledgers

atomic-repository/src/repository/changes.rs:1710–1752  ·  view source on GitHub ↗

List recent session ledgers, newest activity first. Recency is the latest turn timestamp, falling back to `ended_at` and then `started_at`. Session ID breaks timestamp ties deterministically.

(
        &self,
        limit: usize,
    )

Source from the content-addressed store, hash-verified

1708 /// Recency is the latest turn timestamp, falling back to `ended_at` and
1709 /// then `started_at`. Session ID breaks timestamp ties deterministically.
1710 pub fn list_session_ledgers(
1711 &self,
1712 limit: usize,
1713 ) -> Result<
1714 Vec<(
1715 atomic_core::change::session::SessionRecord,
1716 Vec<atomic_core::change::session::SessionTurn>,
1717 )>,
1718 RepositoryError,
1719 > {
1720 let txn = self
1721 .pristine
1722 .read_txn()
1723 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1724 let records = txn
1725 .list_session_records()
1726 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1727 let mut ledgers = Vec::with_capacity(records.len());
1728 for record in records {
1729 let turns = txn
1730 .get_session_turns(&record.session_id)
1731 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1732 ledgers.push((record, turns));
1733 }
1734 ledgers.sort_by(|(a_record, a_turns), (b_record, b_turns)| {
1735 let activity =
1736 |record: &atomic_core::change::session::SessionRecord,
1737 turns: &[atomic_core::change::session::SessionTurn]| {
1738 atomic_core::types::timestamp::epoch_millis(
1739 turns
1740 .last()
1741 .map(|turn| turn.timestamp)
1742 .or(record.ended_at)
1743 .unwrap_or(record.started_at),
1744 )
1745 };
1746 activity(b_record, b_turns)
1747 .cmp(&activity(a_record, a_turns))
1748 .then_with(|| a_record.session_id.cmp(&b_record.session_id))
1749 });
1750 ledgers.truncate(limit);
1751 Ok(ledgers)
1752 }
1753
1754 // =========================================================================
1755 // Session Data Queries (Sherpa-enriched provenance)

Callers 2

show_recent_sessionsFunction · 0.80
list_sessionsMethod · 0.80

Calls 9

epoch_millisFunction · 0.85
read_txnMethod · 0.80
list_session_recordsMethod · 0.80
get_session_turnsMethod · 0.80
lastMethod · 0.80
truncateMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45
cmpMethod · 0.45

Tested by

no test coverage detected