**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.
This commit is contained in:
David Snelling 2025-08-01 16:23:25 -07:00
parent 90eccd75aa
commit d2c1dd14e1

View file

@ -4292,7 +4292,12 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
)
// 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) {