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

Method list_session_ledgers

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

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