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,
)
| 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) |
no test coverage detected