(directory: string, options?: { limit?: number })
| 249 | }) |
| 250 | |
| 251 | async function loadSessions(directory: string, options?: { limit?: number }) { |
| 252 | const key = directoryKey(directory) |
| 253 | const pending = sessionLoads.get(key) |
| 254 | if (pending) { |
| 255 | await pending |
| 256 | return loadSessions(directory, options) |
| 257 | } |
| 258 | |
| 259 | children.pin(key) |
| 260 | const [store, setStore] = children.child(directory, { bootstrap: false }) |
| 261 | const meta = sessionMeta.get(key) |
| 262 | const retainedLimit = Math.max(store.limit, options?.limit ?? 0, meta?.limit ?? 0) |
| 263 | if (meta && meta.limit >= retainedLimit) { |
| 264 | const next = trimSessions(store.session, { |
| 265 | limit: retainedLimit, |
| 266 | permission: session.data.permission, |
| 267 | }) |
| 268 | if (next.length !== store.session.length) { |
| 269 | setStore("session", reconcile(next, { key: "id" })) |
| 270 | } |
| 271 | children.unpin(key) |
| 272 | return |
| 273 | } |
| 274 | |
| 275 | const limit = Math.max(retainedLimit + SESSION_RECENT_LIMIT, SESSION_RECENT_LIMIT) |
| 276 | const promise = queryClient |
| 277 | .fetchQuery({ |
| 278 | ...queryOptionsApi.sessions(key), |
| 279 | queryFn: () => |
| 280 | loadRootSessionsWithFallback({ |
| 281 | directory, |
| 282 | limit, |
| 283 | list: (query) => serverSDK.client.session.list(query), |
| 284 | }) |
| 285 | .then((x) => { |
| 286 | const nonArchived = (x.data ?? []) |
| 287 | .filter((s) => !!s?.id) |
| 288 | .filter((s) => !s.time?.archived) |
| 289 | .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)) |
| 290 | const limit = Math.max(store.limit, options?.limit ?? 0, sessionMeta.get(key)?.limit ?? 0) |
| 291 | const childSessions = store.session.filter((s) => !!s.parentID) |
| 292 | const next = trimSessions([...nonArchived, ...childSessions], { |
| 293 | limit, |
| 294 | permission: session.data.permission, |
| 295 | }) |
| 296 | batch(() => { |
| 297 | next.forEach(session.remember) |
| 298 | setStore( |
| 299 | "sessionTotal", |
| 300 | estimateRootSessionTotal({ |
| 301 | count: nonArchived.length, |
| 302 | limit: x.limit, |
| 303 | limited: x.limited, |
| 304 | }), |
| 305 | ) |
| 306 | setStore("session", reconcile(next, { key: "id" })) |
| 307 | }) |
| 308 | sessionMeta.set(key, { limit }) |
nothing calls this directly
no test coverage detected