MCPcopy Index your code
hub / github.com/codeaashu/claude-code / readAllAndSort

Function readAllAndSort

src/utils/listSessionsImpl.ts:278–299  ·  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

276 * from readSessionLite. Matches pre-refactor I/O cost (no extra stats).
277 */
278async 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)

Callers 1

listSessionsImplFunction · 0.85

Calls 3

valuesMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected