[PR #6807] perf: filter archived sessions and sort by update time in session list API #12119

Open
opened 2026-02-16 18:17:03 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6807

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6807 **State:** open **Merged:** No --- ## 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) ```typescript 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.
yindo added the pull-request label 2026-02-16 18:17:03 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12119