chore: keys function requires sortKey, add allKeys

This commit is contained in:
Tadeuchi
2023-04-20 12:41:03 +02:00
committed by just_ppe
parent 5e55fda5f8
commit cdb9550acc
2 changed files with 9 additions and 3 deletions

View File

@@ -66,7 +66,7 @@ export interface SortKeyCache<V> {
/**
* Returns keys for a specified range
*/
keys(sortKey?: string, options?: SortKeyCacheRangeOptions): Promise<string[]>;
keys(sortKey: string, options?: SortKeyCacheRangeOptions): Promise<string[]>;
/**
* Returns a key value map for a specified range

View File

@@ -272,7 +272,7 @@ export class LevelDbCache<V> implements SortKeyCache<V> {
return lastSortKey == '' ? null : lastSortKey;
}
async keys(sortKey?: string, options?: SortKeyCacheRangeOptions): Promise<string[]> {
async keys(sortKey: string, options?: SortKeyCacheRangeOptions): Promise<string[]> {
return Array.from((await this.kvMap(sortKey, options)).keys());
}
@@ -360,7 +360,7 @@ export class LevelDbCache<V> implements SortKeyCache<V> {
entriesStored = 1;
}
const contracts = await this.keys();
const contracts = await this.allKeys();
for (let i = 0; i < contracts.length; i++) {
const contractCache = this.db.sublevel<string, ClientValueWrapper<V>>(contracts[i], this.subLevelOptions);
@@ -378,4 +378,10 @@ export class LevelDbCache<V> implements SortKeyCache<V> {
return null;
}
private async allKeys(): Promise<string[]> {
return (await this.db.keys().all())
.filter((k) => k != this.ongoingTransactionMark)
.map((k) => this.extractOriginalKey(k));
}
}