perf(app): use cursor session history loading (#17329)

This commit is contained in:
Shoubhit Dash
2026-03-13 16:43:41 +05:30
committed by GitHub
parent 80f91d3fd9
commit 46ba9c8170
4 changed files with 102 additions and 23 deletions

View File

@@ -41,8 +41,8 @@ import {
getSessionPrefetch,
isSessionPrefetchCurrent,
runSessionPrefetch,
SESSION_PREFETCH_TTL,
setSessionPrefetch,
shouldSkipSessionPrefetch,
} from "@/context/global-sync/session-prefetch"
import { useNotification } from "@/context/notification"
import { usePermission } from "@/context/permission"
@@ -770,9 +770,11 @@ export default function Layout(props: ParentProps) {
const next = items.map((x) => x.info).filter((m): m is Message => !!m?.id)
const sorted = mergeByID([], next)
const stale = markPrefetched(directory, sessionID)
const cursor = messages.response.headers.get("x-next-cursor") ?? undefined
const meta = {
limit: prefetchChunk,
complete: sorted.length < prefetchChunk,
limit: sorted.length,
cursor,
complete: !cursor,
at: Date.now(),
}
@@ -846,10 +848,12 @@ export default function Layout(props: ParentProps) {
const [store] = globalSync.child(directory, { bootstrap: false })
const cached = untrack(() => {
if (store.message[session.id] === undefined) return false
const info = getSessionPrefetch(directory, session.id)
if (!info) return false
return Date.now() - info.at < SESSION_PREFETCH_TTL
return shouldSkipSessionPrefetch({
message: store.message[session.id] !== undefined,
info,
chunk: prefetchChunk,
})
})
if (cached) return