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,
)
| 1304 | /// Recency is the latest turn timestamp, falling back to `ended_at` and |
| 1305 | /// then `started_at`. Session ID breaks timestamp ties deterministically. |
| 1306 | pub fn list_session_ledgers( |
| 1307 | &self, |
| 1308 | limit: usize, |
| 1309 | ) -> Result< |
| 1310 | Vec<( |
| 1311 | atomic_core::change::session::SessionRecord, |
| 1312 | Vec<atomic_core::change::session::SessionTurn>, |
| 1313 | )>, |
| 1314 | RepositoryError, |
| 1315 | > { |
| 1316 | let txn = self |
| 1317 | .pristine |
| 1318 | .read_txn() |
| 1319 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 1320 | let records = txn |
| 1321 | .list_session_records() |
| 1322 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 1323 | let mut ledgers = Vec::with_capacity(records.len()); |
| 1324 | for record in records { |
| 1325 | let turns = txn |
| 1326 | .get_session_turns(&record.session_id) |
| 1327 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 1328 | ledgers.push((record, turns)); |
| 1329 | } |
| 1330 | ledgers.sort_by(|(a_record, a_turns), (b_record, b_turns)| { |
| 1331 | let activity = |
| 1332 | |record: &atomic_core::change::session::SessionRecord, |
| 1333 | turns: &[atomic_core::change::session::SessionTurn]| { |
| 1334 | turns |
| 1335 | .last() |
| 1336 | .map(|turn| turn.timestamp) |
| 1337 | .or(record.ended_at) |
| 1338 | .unwrap_or(record.started_at) |
| 1339 | }; |
| 1340 | activity(b_record, b_turns) |
| 1341 | .cmp(&activity(a_record, a_turns)) |
| 1342 | .then_with(|| a_record.session_id.cmp(&b_record.session_id)) |
| 1343 | }); |
| 1344 | ledgers.truncate(limit); |
| 1345 | Ok(ledgers) |
| 1346 | } |
| 1347 | |
| 1348 | // ========================================================================= |
| 1349 | // Session Data Queries (Sherpa-enriched provenance) |
no test coverage detected