mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
perf: store the session cache in day pieces (#1550)
* Store the session cache in day pieces with a per-provider index Layout v10: a provider's files live in pieces by the UTC day of their newest call, each with a key file, and an index row per file (piece, fingerprint, call span, v9 month) read on every load. A ranged load reads the index, the key files and only the members it reports on; a save rewrites only the pieces it touched. Rows keep v9's full-load order and month scope, so orphans, the first-paint snapshot and dedup see what they saw on v9. The v9 month shards re-lay out once, streaming, and are removed after v10 publishes. * Skip cached transcripts outside a narrow query's months when unchanged v9 could not see them, so every narrow query re-parsed each older Claude transcript it discovered and republished the cache. The index knows their fingerprint; an unchanged one needs nothing, a changed one still re-parses as if uncached. * Read piece members in batches through one buffer, and full loads concurrently * Write piece key files without a sync; rebuild lost keys from the piece * Changelog: day pieces * Seed dedup with the keys of unchanged transcripts outside the query's months before a whole-file parse * Upgrade-path check: verify the v10 envelope, indexes, pieces and key files
This commit is contained in:
parent
3f14d95118
commit
e5dff62fa1
14 changed files with 1397 additions and 800 deletions
|
|
@ -29,6 +29,7 @@ import {
|
|||
type SessionCache,
|
||||
beginColdHydration,
|
||||
cacheEntriesInLoadOrder,
|
||||
cacheHiddenFingerprint,
|
||||
cacheStubs,
|
||||
cleanupOrphanedTempFiles,
|
||||
computeEnvFingerprint,
|
||||
|
|
@ -42,6 +43,7 @@ import {
|
|||
isCacheDirty,
|
||||
isCacheStub,
|
||||
loadCache,
|
||||
loadCacheHiddenKeys,
|
||||
loadCacheStubs,
|
||||
markCacheDirty,
|
||||
markProviderComplete,
|
||||
|
|
@ -2062,6 +2064,7 @@ async function scanProjectDirs(
|
|||
}))
|
||||
}
|
||||
const servedStubs: string[][][] = []
|
||||
const hiddenUnchanged: string[] = []
|
||||
|
||||
for (const [i, { filePath, dirName, source }] of discovered.entries()) {
|
||||
allDiscoveredFiles.add(filePath)
|
||||
|
|
@ -2071,7 +2074,13 @@ async function scanProjectDirs(
|
|||
const cached = section.files[filePath]
|
||||
const stub = cached ? undefined : stubs?.get(filePath)
|
||||
const action = reconcileFile(fp, cached ?? stub)
|
||||
if (!readOnly && deferToBackgroundFill(filePath, fp, cached ?? stub)) {
|
||||
// Cached, but in no month this range reports on, and unchanged: nothing to
|
||||
// parse or serve. A changed one re-parses as if uncached, as it always did.
|
||||
const hidden = cached || stub || readOnly ? undefined : cacheHiddenFingerprint(diskCache, 'claude', filePath)
|
||||
if (hidden && reconcileFile(fp, { fingerprint: hidden }).action === 'unchanged') {
|
||||
hiddenUnchanged.push(filePath)
|
||||
continue
|
||||
} else if (!readOnly && deferToBackgroundFill(filePath, fp, cached ?? stub)) {
|
||||
continue
|
||||
} else if (stub && (readOnly || action.action === 'unchanged')) {
|
||||
if (readOnly && action.action !== 'unchanged') readOnlyServedStale = true
|
||||
|
|
@ -2134,6 +2143,11 @@ async function scanProjectDirs(
|
|||
}
|
||||
}
|
||||
for (const keys of servedStubs) for (const turn of keys) for (const key of turn) seenMsgIds.add(key)
|
||||
// Only a whole-file parse can replay an older transcript's message ids (a
|
||||
// fork or resume); an append's new region never does, so it reads no keys.
|
||||
if (hiddenUnchanged.length > 0 && changedFiles.some(f => !f.append)) {
|
||||
for (const keys of await loadCacheHiddenKeys(diskCache, 'claude', hiddenUnchanged)) for (const turn of keys) for (const key of turn) seenMsgIds.add(key)
|
||||
}
|
||||
|
||||
const parseProgress = createScanProgress('parsing changed claude sessions', changedFiles.length)
|
||||
const progressTotal = changedFiles.length
|
||||
|
|
|
|||
1529
src/session-cache.ts
1529
src/session-cache.ts
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue