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

Method list_session_ledgers

atomic-repository/src/repository/changes.rs:1763–1805  ·  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

1761 /// Recency is the latest turn timestamp, falling back to `ended_at` and
1762 /// then `started_at`. Session ID breaks timestamp ties deterministically.
1763 pub fn list_session_ledgers(
1764 &self,
1765 limit: usize,
1766 ) -> Result<
1767 Vec<(
1768 atomic_core::change::session::SessionRecord,
1769 Vec<atomic_core::change::session::SessionTurn>,
1770 )>,
1771 RepositoryError,
1772 > {
1773 let txn = self
1774 .pristine
1775 .read_txn()
1776 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1777 let records = txn
1778 .list_session_records()
1779 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1780 let mut ledgers = Vec::with_capacity(records.len());
1781 for record in records {
1782 let turns = txn
1783 .get_session_turns(&record.session_id)
1784 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1785 ledgers.push((record, turns));
1786 }
1787 ledgers.sort_by(|(a_record, a_turns), (b_record, b_turns)| {
1788 let activity =
1789 |record: &atomic_core::change::session::SessionRecord,
1790 turns: &[atomic_core::change::session::SessionTurn]| {
1791 atomic_core::types::timestamp::epoch_millis(
1792 turns
1793 .last()
1794 .map(|turn| turn.timestamp)
1795 .or(record.ended_at)
1796 .unwrap_or(record.started_at),
1797 )
1798 };
1799 activity(b_record, b_turns)
1800 .cmp(&activity(a_record, a_turns))
1801 .then_with(|| a_record.session_id.cmp(&b_record.session_id))
1802 });
1803 ledgers.truncate(limit);
1804 Ok(ledgers)
1805 }
1806
1807 // =========================================================================
1808 // Session Data Queries (Sherpa-enriched provenance)

Callers 3

show_recent_sessionsFunction · 0.80
list_sessionsMethod · 0.80
resolve_with_sessionFunction · 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