diff --git a/packages/core/storage/src/storage.ts b/packages/core/storage/src/storage.ts index f317c7de0..8f13efc5f 100644 --- a/packages/core/storage/src/storage.ts +++ b/packages/core/storage/src/storage.ts @@ -61,8 +61,6 @@ export class AlwatrStorage { /** * All document ids in array. - * - * Contain `_last`! */ get keys(): Array { if (this._keys === null) { @@ -72,7 +70,7 @@ export class AlwatrStorage { } /** - * Size of the storage (count `_last`). + * Size of the storage. */ get length(): number { return this.keys.length; @@ -132,7 +130,6 @@ export class AlwatrStorage { const documentObject = this._storage[documentId]; if (typeof documentObject === 'string') { - // for example _last return this.get(documentObject); } else if (documentObject == null) { @@ -167,7 +164,7 @@ export class AlwatrStorage { this._logger.logMethodArgs('set', documentObject._id); const oldData = this._storage[documentObject._id]; - if (oldData == null) this._keys = null; // Clear cached keys on new docId + if (oldData == null) this._keys = null; // Clear cached keys if (fastInstance !== true) { documentObject = JSON.parse(JSON.stringify(documentObject)); @@ -179,7 +176,6 @@ export class AlwatrStorage { documentObject._createdBy = oldData?._createdBy ?? documentObject._updatedBy; documentObject._rev = (oldData?._rev ?? 0) + 1; - this._storage._last = documentObject._id; this._storage[documentObject._id] = documentObject; this.save(); @@ -203,6 +199,10 @@ export class AlwatrStorage { } // else delete this._storage[documentId]; + + // Clear cached keys + this._keys = null; + this.save(); return true; } @@ -224,7 +224,6 @@ export class AlwatrStorage { async forAll(callbackfn: (documentObject: DocumentType) => void | false | Promise): Promise { const keys = this.keys; for (const documentId of keys) { - if (documentId === '_last') continue; // prevent to duplicate latest key. const documentObject = this.get(documentId); if (documentObject != null) { const retVal = await callbackfn(documentObject); @@ -272,5 +271,8 @@ export class AlwatrStorage { this.forceSave(); } this._storage = {}; + + // Clear cached keys + this._keys = null; } } diff --git a/packages/core/storage/src/type.ts b/packages/core/storage/src/type.ts index ad145c32a..1e070b795 100644 --- a/packages/core/storage/src/type.ts +++ b/packages/core/storage/src/type.ts @@ -10,9 +10,7 @@ export interface DocumentObject { _updatedBy: string; } -export type DocumentListStorage = Record & { - _last?: string; -}; +export type DocumentListStorage = Record export type AlwatrStorageConfig = { /**