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,
)
| 1404 | /// Recency is the latest turn timestamp, falling back to `ended_at` and |
| 1405 | /// then `started_at`. Session ID breaks timestamp ties deterministically. |
| 1406 | pub fn list_session_ledgers( |
| 1407 | &self, |
| 1408 | limit: usize, |
| 1409 | ) -> Result< |
| 1410 | Vec<( |
| 1411 | atomic_core::change::session::SessionRecord, |
| 1412 | Vec<atomic_core::change::session::SessionTurn>, |
| 1413 | )>, |
| 1414 | RepositoryError, |
| 1415 | > { |
| 1416 | let txn = self |
| 1417 | .pristine |
| 1418 | .read_txn() |
| 1419 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 1420 | let records = txn |
| 1421 | .list_session_records() |
| 1422 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 1423 | let mut ledgers = Vec::with_capacity(records.len()); |
| 1424 | for record in records { |
| 1425 | let turns = txn |
| 1426 | .get_session_turns(&record.session_id) |
| 1427 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 1428 | ledgers.push((record, turns)); |
| 1429 | } |
| 1430 | ledgers.sort_by(|(a_record, a_turns), (b_record, b_turns)| { |
| 1431 | let activity = |
| 1432 | |record: &atomic_core::change::session::SessionRecord, |
| 1433 | turns: &[atomic_core::change::session::SessionTurn]| { |
| 1434 | turns |
| 1435 | .last() |
| 1436 | .map(|turn| turn.timestamp) |
| 1437 | .or(record.ended_at) |
| 1438 | .unwrap_or(record.started_at) |
| 1439 | }; |
| 1440 | activity(b_record, b_turns) |
| 1441 | .cmp(&activity(a_record, a_turns)) |
| 1442 | .then_with(|| a_record.session_id.cmp(&b_record.session_id)) |
| 1443 | }); |
| 1444 | ledgers.truncate(limit); |
| 1445 | Ok(ledgers) |
| 1446 | } |
| 1447 | |
| 1448 | // ========================================================================= |
| 1449 | // Session Data Queries (Sherpa-enriched provenance) |
no test coverage detected