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

Method list_session_ledgers

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

1320 /// Recency is the latest turn timestamp, falling back to `ended_at` and
1321 /// then `started_at`. Session ID breaks timestamp ties deterministically.
1322 pub fn list_session_ledgers(
1323 &self,
1324 limit: usize,
1325 ) -> Result<
1326 Vec<(
1327 atomic_core::change::session::SessionRecord,
1328 Vec<atomic_core::change::session::SessionTurn>,
1329 )>,
1330 RepositoryError,
1331 > {
1332 let txn = self
1333 .pristine
1334 .read_txn()
1335 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1336 let records = txn
1337 .list_session_records()
1338 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1339 let mut ledgers = Vec::with_capacity(records.len());
1340 for record in records {
1341 let turns = txn
1342 .get_session_turns(&record.session_id)
1343 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1344 ledgers.push((record, turns));
1345 }
1346 ledgers.sort_by(|(a_record, a_turns), (b_record, b_turns)| {
1347 let activity =
1348 |record: &atomic_core::change::session::SessionRecord,
1349 turns: &[atomic_core::change::session::SessionTurn]| {
1350 turns
1351 .last()
1352 .map(|turn| turn.timestamp)
1353 .or(record.ended_at)
1354 .unwrap_or(record.started_at)
1355 };
1356 activity(b_record, b_turns)
1357 .cmp(&activity(a_record, a_turns))
1358 .then_with(|| a_record.session_id.cmp(&b_record.session_id))
1359 });
1360 ledgers.truncate(limit);
1361 Ok(ledgers)
1362 }
1363
1364 // =========================================================================
1365 // Session Data Queries (Sherpa-enriched provenance)

Callers 1

show_recent_sessionsFunction · 0.80

Calls 8

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

Tested by

no test coverage detected