perf: optimize /api/sessions endpoint response payload

Slim down SessionSummary responses to reduce payload size:
- Replace full todos array with computed todoProgress summary
- Replace metadata object with only necessary fields (name, path, summary.text)
- Remove unused fields (thinking, createdAt, permissionMode, modelMode)
- Refactor sorting to work on full Session objects before mapping

This significantly reduces /api/sessions response size, especially for
sessions with many todos or tools.
This commit is contained in:
weishu
2025-12-19 15:10:23 +08:00
parent bb514482a2
commit db888d90f8
3 changed files with 40 additions and 26 deletions
+3 -5
View File
@@ -58,11 +58,9 @@ function getSessionTitle(session: SessionSummary): string {
}
function getTodoProgress(session: SessionSummary): { completed: number; total: number } | null {
if (!session.todos || session.todos.length === 0) return null
const total = session.todos.length
const completed = session.todos.filter(t => t.status === 'completed').length
if (completed === total) return null
return { completed, total }
if (!session.todoProgress) return null
if (session.todoProgress.completed === session.todoProgress.total) return null
return session.todoProgress
}
export function SessionList(props: {