opencode icon indicating copy to clipboard operation
opencode copied to clipboard

perf: filter archived sessions and sort by update time in session list API

Open usvimal opened this issue 1 week ago • 0 comments

Summary

  • Filter out archived sessions server-side in the /session list 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:

  1. Unnecessary data transfer for archived sessions
  2. Client-side filtering overhead
  3. Sessions returned in arbitrary order

Solution

Use pipe() with filter() and sortBy() from remeda to:

  1. Exclude sessions where time.archived is set
  2. 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.

usvimal avatar Jan 04 '26 05:01 usvimal