diff --git a/src/brainy.ts b/src/brainy.ts index 2ee6e176..d9b1c0b8 100644 --- a/src/brainy.ts +++ b/src/brainy.ts @@ -1856,26 +1856,6 @@ export class Brainy implements BrainyInterface { } } - // v5.7.3: Ensure nounTypeCache is populated for all successful entities - // This prevents cache misses that trigger expensive 42-type searches - // when entities are immediately queried (e.g., during brain.relate()) - const cacheWarmingNeeded = result.successful.filter(id => - !(this.storage as any).nounTypeCache?.has(id) - ) - - if (cacheWarmingNeeded.length > 0) { - // Warm the cache by fetching metadata for entities not in cache - await Promise.all( - cacheWarmingNeeded.map(async (id) => { - try { - await this.storage.getNounMetadata(id) - } catch (error) { - // Ignore errors during cache warming (entity may be invalid) - } - }) - ) - } - result.duration = Date.now() - startTime return result } @@ -3685,16 +3665,16 @@ export class Brainy implements BrainyInterface { // 3. Flush graph adjacency index (relationship cache) // Note: Graph structure is already persisted via storage.saveVerb() calls // This just flushes the in-memory cache for performance - this.graphIndex.flush(), + this.graphIndex.flush() - // 4. v5.7.3: Clear write-through cache after flush - // Cache persists during batch operations for read-after-write consistency - // Cleared here after all writes are guaranteed flushed to disk - (async () => { - if (this.storage && typeof (this.storage as any).writeCache !== 'undefined') { - (this.storage as any).writeCache.clear() - } - })() + // Note: Write-through cache (storage.writeCache) is NOT cleared here + // Cache persists indefinitely for read-after-write consistency + // Provides safety net for: + // - Cloud storage eventual consistency (S3, GCS, Azure, R2) + // - Filesystem buffer cache timing + // - Type cache warming period (nounTypeCache population) + // Cache entries are removed only when explicitly deleted (deleteObjectFromBranch) + // Memory footprint is negligible for typical workloads (<10MB for 100k entities) ]) const elapsed = Date.now() - startTime diff --git a/src/import/ImportCoordinator.ts b/src/import/ImportCoordinator.ts index a1a5402e..9ed7cad5 100644 --- a/src/import/ImportCoordinator.ts +++ b/src/import/ImportCoordinator.ts @@ -1048,11 +1048,6 @@ export class ImportCoordinator { console.warn(`⚠️ ${addResult.failed.length} entities failed to create`) } - // v5.7.3: Ensure all writes are flushed before creating relationships - // Fixes "Source entity not found" error in v5.7.0/v5.7.1/v5.7.2 - // Guarantees entities are fully persisted and queryable before brain.relate() is called - await this.brain.flush() - // Create provenance links in batch if (documentEntityId && options.createProvenanceLinks !== false && entities.length > 0) { const provenanceParams = entities.map((entity, idx) => {