From 46ba9c81703fc6e7db7e623a607eeaab94fcd00f Mon Sep 17 00:00:00 2001 From: Shoubhit Dash Date: Fri, 13 Mar 2026 16:43:41 +0530 Subject: perf(app): use cursor session history loading (#17329) --- packages/app/src/pages/layout.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'packages/app/src/pages') diff --git a/packages/app/src/pages/layout.tsx b/packages/app/src/pages/layout.tsx index ed2221846..9b964b4b5 100644 --- a/packages/app/src/pages/layout.tsx +++ b/packages/app/src/pages/layout.tsx @@ -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 -- cgit v1.2.3