From d2c1dd14e1e3d30025ce0d80d3085b5f3a11dd55 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Fri, 1 Aug 2025 16:23:25 -0700 Subject: [PATCH] **fix(storage): ensure index clearing and statistics flushing for consistency** - Updated `brainyData.ts`: - Made `this.index.clear()` asynchronous to prevent potential timing issues during storage test. - Added conditional `this.storage.flushStatisticsToStorage()` call to ensure statistics are properly flushed, avoiding data inconsistencies. **Purpose**: Enhance storage consistency by ensuring proper index clearing and statistics flushing during tests. --- src/brainyData.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/brainyData.ts b/src/brainyData.ts index 29c7fff4..be83fa59 100644 --- a/src/brainyData.ts +++ b/src/brainyData.ts @@ -4292,7 +4292,12 @@ export class BrainyData implements BrainyDataInterface { ) // Explicitly clear the index for the storage test - this.index.clear() + await this.index.clear() + + // Ensure statistics are properly flushed to avoid inconsistencies + if (this.storage) { + await this.storage.flushStatisticsToStorage() + } } else { // Re-add all nouns to the index for normal operation for (const noun of data.nouns) {