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