Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
1d4832a2a4
1 changed files with 20 additions and 16 deletions
|
@ -241,20 +241,27 @@ class IndexedDBLogStore {
|
||||||
|
|
||||||
// Returns: a string representing the concatenated logs for this ID.
|
// Returns: a string representing the concatenated logs for this ID.
|
||||||
function fetchLogs(id) {
|
function fetchLogs(id) {
|
||||||
const o = db.transaction("logs", "readonly").objectStore("logs");
|
const objectStore = db.transaction("logs", "readonly").objectStore("logs");
|
||||||
return selectQuery(o.index("id"), IDBKeyRange.only(id),
|
|
||||||
(cursor) => {
|
return new Promise((resolve, reject) => {
|
||||||
return {
|
const query = objectStore.index("id").openCursor(IDBKeyRange.only(id), 'next');
|
||||||
lines: cursor.value.lines,
|
let lines = '';
|
||||||
index: cursor.value.index,
|
query.onerror = (event) => {
|
||||||
|
reject(new Error("Query failed: " + event.target.errorCode));
|
||||||
|
};
|
||||||
|
query.onsuccess = (event) => {
|
||||||
|
const cursor = event.target.result;
|
||||||
|
if (!cursor) {
|
||||||
|
resolve(lines);
|
||||||
|
return; // end of results
|
||||||
|
}
|
||||||
|
lines += cursor.value.lines;
|
||||||
|
if (lines.length >= MAX_LOG_SIZE) {
|
||||||
|
resolve(lines);
|
||||||
|
} else {
|
||||||
|
cursor.continue();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}).then((linesArray) => {
|
|
||||||
// We have been storing logs periodically, so string them all
|
|
||||||
// together *in order of index* now
|
|
||||||
linesArray.sort((a, b) => {
|
|
||||||
return a.index - b.index;
|
|
||||||
});
|
|
||||||
return linesArray.map((l) => l.lines).join("");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,9 +329,6 @@ class IndexedDBLogStore {
|
||||||
if (i > 0 && size + lines.length > MAX_LOG_SIZE) {
|
if (i > 0 && size + lines.length > MAX_LOG_SIZE) {
|
||||||
// the remaining log IDs should be removed. If we go out of
|
// the remaining log IDs should be removed. If we go out of
|
||||||
// bounds this is just []
|
// bounds this is just []
|
||||||
//
|
|
||||||
// XXX: there's nothing stopping the current session exceeding
|
|
||||||
// MAX_LOG_SIZE. We ought to think about culling it.
|
|
||||||
removeLogIds = allLogIds.slice(i + 1);
|
removeLogIds = allLogIds.slice(i + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue