mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-01-10 20:17:32 +01:00
delete extra log items when over limit,to not have to delete every flush
This commit is contained in:
parent
ee4a382578
commit
e629a93edd
@ -60,19 +60,20 @@ export class IDBLogger extends BaseLogger {
|
|||||||
for(const i of this._queuedItems) {
|
for(const i of this._queuedItems) {
|
||||||
logs.add(i);
|
logs.add(i);
|
||||||
}
|
}
|
||||||
// TODO: delete more than needed so we don't delete on every flush?
|
|
||||||
// trim logs if needed
|
|
||||||
const itemCount = await reqAsPromise(logs.count());
|
const itemCount = await reqAsPromise(logs.count());
|
||||||
if (itemCount > this._limit) {
|
if (itemCount > this._limit) {
|
||||||
let currentCount = itemCount;
|
// delete an extra 10% so we don't need to delete every time we flush
|
||||||
|
let deleteAmount = (itemCount - this._limit) + Math.round(0.1 * this._limit);
|
||||||
await iterateCursor(logs.openCursor(), (_, __, cursor) => {
|
await iterateCursor(logs.openCursor(), (_, __, cursor) => {
|
||||||
cursor.delete();
|
cursor.delete();
|
||||||
currentCount -= 1;
|
deleteAmount -= 1;
|
||||||
return {done: currentCount <= this._limit};
|
return {done: deleteAmount === 0};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await txnAsPromise(txn);
|
await txnAsPromise(txn);
|
||||||
this._queuedItems.splice(0, amount);
|
this._queuedItems.splice(0, amount);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("Could not flush logs", err);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
db.close();
|
db.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user