* Read-all path for when no limit/offset is set. Skips the stat pass * entirely — reads every candidate, then sorts/dedups on real mtimes * from readSessionLite. Matches pre-refactor I/O cost (no extra stats).
(candidates: Candidate[])
| 276 | * from readSessionLite. Matches pre-refactor I/O cost (no extra stats). |
| 277 | */ |
| 278 | async function readAllAndSort(candidates: Candidate[]): Promise<SessionInfo[]> { |
| 279 | const all = await Promise.all(candidates.map(readCandidate)) |
| 280 | const byId = new Map<string, SessionInfo>() |
| 281 | for (const s of all) { |
| 282 | if (!s) continue |
| 283 | const existing = byId.get(s.sessionId) |
| 284 | if (!existing || s.lastModified > existing.lastModified) { |
| 285 | byId.set(s.sessionId, s) |
| 286 | } |
| 287 | } |
| 288 | const sessions = [...byId.values()] |
| 289 | sessions.sort((a, b) => |
| 290 | b.lastModified !== a.lastModified |
| 291 | ? b.lastModified - a.lastModified |
| 292 | : b.sessionId < a.sessionId |
| 293 | ? -1 |
| 294 | : b.sessionId > a.sessionId |
| 295 | ? 1 |
| 296 | : 0, |
| 297 | ) |
| 298 | return sessions |
| 299 | } |
| 300 | |
| 301 | // --------------------------------------------------------------------------- |
| 302 | // Project directory enumeration (single-project vs all-projects) |
no test coverage detected