Merge d37c16d3c8 into ae614d919f
commit
77b4d2435b
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue