mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-02-08 18:48:18 +01:00
make log id autoinc
This commit is contained in:
parent
204cc25304
commit
417e920ea0
@ -20,7 +20,6 @@ import {
|
|||||||
reqAsPromise,
|
reqAsPromise,
|
||||||
iterateCursor,
|
iterateCursor,
|
||||||
fetchResults,
|
fetchResults,
|
||||||
encodeUint64
|
|
||||||
} from "../matrix/storage/idb/utils.js";
|
} from "../matrix/storage/idb/utils.js";
|
||||||
import {BaseLogger} from "./BaseLogger.js";
|
import {BaseLogger} from "./BaseLogger.js";
|
||||||
|
|
||||||
@ -30,9 +29,6 @@ export class IDBLogger extends BaseLogger {
|
|||||||
const {name, flushInterval = 60 * 1000, limit = 3000} = options;
|
const {name, flushInterval = 60 * 1000, limit = 3000} = options;
|
||||||
this._name = name;
|
this._name = name;
|
||||||
this._limit = limit;
|
this._limit = limit;
|
||||||
// does not get loaded from idb on startup as we only use it to
|
|
||||||
// differentiate between two items with the same start time
|
|
||||||
this._itemCounter = 0;
|
|
||||||
this._queuedItems = this._loadQueuedItems();
|
this._queuedItems = this._loadQueuedItems();
|
||||||
// TODO: also listen for unload just in case sync keeps on running after pagehide is fired?
|
// TODO: also listen for unload just in case sync keeps on running after pagehide is fired?
|
||||||
window.addEventListener("pagehide", this, false);
|
window.addEventListener("pagehide", this, false);
|
||||||
@ -101,13 +97,11 @@ export class IDBLogger extends BaseLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_openDB() {
|
_openDB() {
|
||||||
return openDatabase(this._name, db => db.createObjectStore("logs", {keyPath: "id"}), 1);
|
return openDatabase(this._name, db => db.createObjectStore("logs", {keyPath: "id", autoIncrement: true}), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
_persistItem(serializedItem) {
|
_persistItem(serializedItem) {
|
||||||
this._itemCounter += 1;
|
|
||||||
this._queuedItems.push({
|
this._queuedItems.push({
|
||||||
id: `${encodeUint64(serializedItem.s)}:${this._itemCounter}`,
|
|
||||||
json: JSON.stringify(serializedItem)
|
json: JSON.stringify(serializedItem)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -127,10 +121,7 @@ export class IDBLogger extends BaseLogger {
|
|||||||
const logs = txn.objectStore("logs");
|
const logs = txn.objectStore("logs");
|
||||||
const storedItems = await fetchResults(logs.openCursor(), () => false);
|
const storedItems = await fetchResults(logs.openCursor(), () => false);
|
||||||
const allItems = storedItems.concat(this._queuedItems);
|
const allItems = storedItems.concat(this._queuedItems);
|
||||||
const sortedItems = allItems.sort((a, b) => {
|
return new IDBLogExport(allItems, this, this._platform);
|
||||||
return a.id > b.id;
|
|
||||||
});
|
|
||||||
return new IDBLogExport(sortedItems, this, this._platform);
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
db.close();
|
db.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user