core: add removeMulti to storage

This commit is contained in:
Ammar Ahmed
2023-11-25 13:17:10 +05:00
parent 50137e0994
commit a7d85cb3f6
2 changed files with 11 additions and 4 deletions

View File

@@ -48,6 +48,10 @@ export default class Storage {
return this.storage.remove(key);
}
removeMulti(...keys) {
return this.storage.removeMulti(...keys);
}
getAllKeys() {
return this.storage.getAllKeys();
}

View File

@@ -96,12 +96,17 @@ class DatabaseLogWriter {
async rotate() {
const logKeys = (await this.storage.getAllKeys()).sort();
const keysToRemove = [];
for (let key of logKeys) {
const keyParts = key.split(":");
if (keyParts.length === 1 || parseInt(keyParts[1]) < Date.now() - WEEK) {
await this.storage.remove(key);
keysToRemove.push(key);
}
}
if (keysToRemove.length) {
await this.storage.removeMulti(...keysToRemove);
}
}
}
@@ -137,9 +142,7 @@ class DatabaseLogManager {
async clear() {
const logKeys = await this.storage.getAllKeys();
for (const key of logKeys) {
await this.storage.remove(key);
}
await this.storage.removeMulti(...logKeys);
}
async delete(key) {