opencode
opencode copied to clipboard
perf: filter archived sessions and sort by update time in session list API
Summary
- Filter out archived sessions server-side in the
/sessionlist endpoint - Sort sessions by most recently updated first (descending)
Problem
The session list API was returning all sessions including archived ones, leaving filtering to the client. This causes:
- Unnecessary data transfer for archived sessions
- Client-side filtering overhead
- Sessions returned in arbitrary order
Solution
Use pipe() with filter() and sortBy() from remeda to:
- Exclude sessions where
time.archivedis set - Sort by
-time.updated(descending, most recent first)
const sessions = pipe(
await Array.fromAsync(Session.list()),
filter((s) => !s.time.archived),
sortBy((s) => -s.time.updated),
)
Note
The client-side code in global-sync.tsx and sync.tsx already does similar filtering/sorting, but doing it server-side reduces data transfer and is more efficient.