summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context/global-sync/session-prefetch.ts
diff options
context:
space:
mode:
authorShoubhit Dash <[email protected]>2026-03-13 16:43:41 +0530
committerGitHub <[email protected]>2026-03-13 16:43:41 +0530
commit46ba9c81703fc6e7db7e623a607eeaab94fcd00f (patch)
tree15e7cb8c2f01e2fa56d83adef333520e57732de0 /packages/app/src/context/global-sync/session-prefetch.ts
parent80f91d3fd912b6fc8d476d1f1ae7d221c08d19e9 (diff)
downloadopencode-46ba9c81703fc6e7db7e623a607eeaab94fcd00f.tar.gz
opencode-46ba9c81703fc6e7db7e623a607eeaab94fcd00f.zip
perf(app): use cursor session history loading (#17329)
Diffstat (limited to 'packages/app/src/context/global-sync/session-prefetch.ts')
-rw-r--r--packages/app/src/context/global-sync/session-prefetch.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/app/src/context/global-sync/session-prefetch.ts b/packages/app/src/context/global-sync/session-prefetch.ts
index 10877b063..608561f85 100644
--- a/packages/app/src/context/global-sync/session-prefetch.ts
+++ b/packages/app/src/context/global-sync/session-prefetch.ts
@@ -4,10 +4,23 @@ export const SESSION_PREFETCH_TTL = 15_000
type Meta = {
limit: number
+ cursor?: string
complete: boolean
at: number
}
+export function shouldSkipSessionPrefetch(input: { message: boolean; info?: Meta; chunk: number; now?: number }) {
+ if (input.message) {
+ if (!input.info) return true
+ if (input.info.complete) return true
+ if (input.info.limit > input.chunk) return true
+ } else {
+ if (!input.info) return false
+ }
+
+ return (input.now ?? Date.now()) - input.info.at < SESSION_PREFETCH_TTL
+}
+
const cache = new Map<string, Meta>()
const inflight = new Map<string, Promise<Meta | undefined>>()
const rev = new Map<string, number>()
@@ -53,11 +66,13 @@ export function setSessionPrefetch(input: {
directory: string
sessionID: string
limit: number
+ cursor?: string
complete: boolean
at?: number
}) {
cache.set(key(input.directory, input.sessionID), {
limit: input.limit,
+ cursor: input.cursor,
complete: input.complete,
at: input.at ?? Date.now(),
})