| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f1afa60 commit d11a663
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,20 +71,13 @@ export interface CachedLoadResultEntry { | |||
| 71 | 71 | } | |
| 72 | 72 | ||
| 73 | 73 | /** | |
| 74 | - * Calculates a unique cache key by updating the hash incrementally. | ||
| 75 | - * This prevents implicit string coercion of large binary content buffers. | ||
| 74 | + * Calculates a unique cache key from the global configuration hash and path. | ||
| 76 | 75 | */ | |
| 77 | - function calculateCacheKey( | ||
| 78 | - globalConfigHash: string, | ||
| 79 | - path: string, | ||
| 80 | - content: string | Uint8Array, | ||
| 81 | - ): string { | ||
| 76 | + function calculateCacheKey(globalConfigHash: string, path: string): string { | ||
| 82 | 77 | const hasher = createContentHash(); | |
| 83 | 78 | hasher.update(globalConfigHash); | |
| 84 | 79 | hasher.update('\0'); | |
| 85 | 80 | hasher.update(path); | |
| 86 | - hasher.update('\0'); | ||
| 87 | - hasher.update(content); | ||
| 88 | 81 | ||
| 89 | 82 | return hasher.digest(); | |
| 90 | 83 | } | |
@@ -154,7 +147,6 @@ async function validateAndHealCacheEntry( | |||
| 154 | 147 | store: PersistentCacheStore<CachedLoadResultEntry>, | |
| 155 | 148 | cacheKey: string, | |
| 156 | 149 | cached: CachedLoadResultEntry, | |
| 157 | - targetFilePath?: string, | ||
| 158 | 150 | ): Promise<boolean> { | |
| 159 | 151 | if (!watchFilesMetadata) { | |
| 160 | 152 | return false; | |
@@ -176,19 +168,7 @@ async function validateAndHealCacheEntry( | |||
| 176 | 168 | return true; | |
| 177 | 169 | } | |
| 178 | 170 | ||
| 179 | - // 2. Target File Path: content hash was already verified by cacheKey lookup, heal metadata if mtime changed | ||
| 180 | - if (targetFilePath && filePath === targetFilePath) { | ||
| 181 | - watchFilesMetadata[filePath] = { | ||
| 182 | - ...expected, | ||
| 183 | - mtimeMs: stats.mtimeMs, | ||
| 184 | - size: stats.size, | ||
| 185 | - }; | ||
| 186 | - healed = true; | ||
| 187 | - | ||
| 188 | - return true; | ||
| 189 | - } | ||
| 190 | - | ||
| 191 | - // 3. Slow Path for dependencies: content hash fallback | ||
| 171 | + // 2. Slow Path: content hash fallback | ||
| 192 | 172 | const currentContent = await readFile(filePath); | |
| 193 | 173 | const currentHash = calculateHash(currentContent); | |
| 194 | 174 | if (currentHash === expected.hash) { | |
@@ -280,17 +260,7 @@ export class PersistentLoadResultCache implements LoadResultCache { | |||
| 280 | 260 | } | |
| 281 | 261 | ||
| 282 | 262 | // 2. Check L2 Persistent Disk Cache | |
| 283 | - let content: string | Uint8Array = ''; | ||
| 284 | - const filePath = extractDiskFilePath(path); | ||
| 285 | - if (filePath) { | ||
| 286 | - try { | ||
| 287 | - content = await readFile(filePath); | ||
| 288 | - } catch { | ||
| 289 | - return undefined; | ||
| 290 | - } | ||
| 291 | - } | ||
| 292 | - | ||
| 293 | - const cacheKey = calculateCacheKey(this.globalConfigHash, path, content); | ||
| 263 | + const cacheKey = calculateCacheKey(this.globalConfigHash, path); | ||
| 294 | 264 | const cached = await this.persistentStore.get(cacheKey); | |
| 295 | 265 | ||
| 296 | 266 | if ( | |
@@ -300,7 +270,6 @@ export class PersistentLoadResultCache implements LoadResultCache { | |||
| 300 | 270 | this.persistentStore, | |
| 301 | 271 | cacheKey, | |
| 302 | 272 | cached, | |
| 303 | - filePath, | ||
| 304 | 273 | )) | |
| 305 | 274 | ) { | |
| 306 | 275 | const result: OnLoadResult = { | |
@@ -340,17 +309,17 @@ export class PersistentLoadResultCache implements LoadResultCache { | |||
| 340 | 309 | } | |
| 341 | 310 | } | |
| 342 | 311 | ||
| 343 | - const cacheKey = calculateCacheKey(this.globalConfigHash, path, content); | ||
| 312 | + const cacheKey = calculateCacheKey(this.globalConfigHash, path); | ||
| 344 | 313 | ||
| 345 | 314 | // Reuse the target file's pre-read content buffer to avoid redundant disk reads (readFile) | |
| 346 | 315 | // during dependency watch file metadata computation. | |
| 347 | 316 | const knownContents = filePath | |
| 348 | 317 | ? new Map<string, string | Uint8Array>([[filePath, content]]) | |
| 349 | 318 | : undefined; | |
| 350 | - const watchFilesMetadata = await computeMetadataForWatchFiles( | ||
| 351 | - result.watchFiles ?? [], | ||
| 352 | - knownContents, | ||
| 319 | + const allWatchFiles = Array.from( | ||
| 320 | + new Set(filePath ? [filePath, ...(result.watchFiles ?? [])] : result.watchFiles), | ||
| 353 | 321 | ); | |
| 322 | + const watchFilesMetadata = await computeMetadataForWatchFiles(allWatchFiles, knownContents); | ||
| 354 | 323 | ||
| 355 | 324 | await this.persistentStore.put(cacheKey, { | |
| 356 | 325 | contents: result.contents, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -193,10 +193,8 @@ export class SqliteCacheStore implements PersistentCacheStore<unknown> { | |||
| 193 | 193 | #queueAccessUpdate(key: string): void { | |
| 194 | 194 | this.#pendingAccessedKeys.add(key); | |
| 195 | 195 | ||
| 196 | - if (this.#pendingAccessedKeys.size >= 100) { | ||
| 197 | - this.#flushAccessUpdates(); | ||
| 198 | - } else if (!this.#flushTimeout) { | ||
| 199 | - this.#flushTimeout = setTimeout(() => this.#flushAccessUpdates(), 500); | ||
| 196 | + if (!this.#flushTimeout) { | ||
| 197 | + this.#flushTimeout = setTimeout(() => this.#flushAccessUpdates(), 1000); | ||
| 200 | 198 | this.#flushTimeout.unref?.(); | |
| 201 | 199 | } | |
| 202 | 200 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments