pull/17848/merge
Rohan Guliani 2026-04-08 05:13:10 +00:00 committed by GitHub
commit 77b4d2435b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 5 deletions

View File

@ -249,8 +249,8 @@ describe("applyDirectoryEvent", () => {
})
test("cleans caches for trimmed sessions on session.created", () => {
const dropped = rootSession({ id: "ses_b" })
const kept = rootSession({ id: "ses_a" })
const dropped = rootSession({ id: "ses_a" })
const kept = rootSession({ id: "ses_b" })
const message = userMessage("msg_1", dropped.id)
const todos: string[] = []
const [store, setStore] = createStore(

View File

@ -10,7 +10,7 @@ export function compareSessionRecent(a: Session, b: Session) {
const aUpdated = sessionUpdatedAt(a)
const bUpdated = sessionUpdatedAt(b)
if (aUpdated !== bUpdated) return bUpdated - aUpdated
return cmp(a.id, b.id)
return cmp(b.id, a.id)
}
export function takeRecentSessions(sessions: Session[], limit: number, cutoff: number) {
@ -39,7 +39,7 @@ export function trimSessions(
const all = input
.filter((s) => !!s?.id)
.filter((s) => !s.time?.archived)
.sort((a, b) => cmp(a.id, b.id))
.sort((a, b) => compareSessionRecent(a, b))
const roots = all.filter((s) => !s.parentID)
const children = all.filter((s) => !!s.parentID)
const base = roots.slice(0, limit)

View File

@ -21,7 +21,7 @@ function sortSessions(now: number) {
const bUpdated = b.time.updated ?? b.time.created
const aRecent = aUpdated > oneMinuteAgo
const bRecent = bUpdated > oneMinuteAgo
if (aRecent && bRecent) return a.id < b.id ? -1 : a.id > b.id ? 1 : 0
if (aRecent && bRecent) return a.id > b.id ? -1 : a.id < b.id ? 1 : 0
if (aRecent && !bRecent) return -1
if (!aRecent && bRecent) return 1
return bUpdated - aUpdated