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: {
+8 -6
View File
@@ -58,16 +58,18 @@ export type Session = {
modelMode?: ModelMode
}
export type SessionSummaryMetadata = {
name?: string
path: string
summary?: { text: string }
}
export type SessionSummary = {
id: string
active: boolean
thinking: boolean
updatedAt: number
createdAt: number
permissionMode: PermissionMode
modelMode: ModelMode
metadata: SessionMetadataSummary | null
todos?: TodoItem[]
metadata: SessionSummaryMetadata | null
todoProgress: { completed: number; total: number } | null
pendingRequestsCount: number
}