MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / readAllAndSort

Function readAllAndSort

source code/utils/listSessionsImpl.ts:280–301  ·  view source on GitHub ↗

* 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[])

Source from the content-addressed store, hash-verified

278 * from readSessionLite. Matches pre-refactor I/O cost (no extra stats).
279 */
280async function readAllAndSort(candidates: Candidate[]): Promise<SessionInfo[]> {
281 const all = await Promise.all(candidates.map(readCandidate))
282 const byId = new Map<string, SessionInfo>()
283 for (const s of all) {
284 if (!s) continue
285 const existing = byId.get(s.sessionId)
286 if (!existing || s.lastModified > existing.lastModified) {
287 byId.set(s.sessionId, s)
288 }
289 }
290 const sessions = [...byId.values()]
291 sessions.sort((a, b) =>
292 b.lastModified !== a.lastModified
293 ? b.lastModified - a.lastModified
294 : b.sessionId < a.sessionId
295 ? -1
296 : b.sessionId > a.sessionId
297 ? 1
298 : 0,
299 )
300 return sessions
301}
302
303// ---------------------------------------------------------------------------
304// Project directory enumeration (single-project vs all-projects)

Callers 1

listSessionsImplFunction · 0.85

Calls 2

setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected