update log timestamp adjustments

This commit is contained in:
tophf 2017-04-27 15:54:55 +03:00
parent f0dc13cd2e
commit 459c2e5ef3

View File

@ -132,19 +132,17 @@ var updater = {
let queue = []; let queue = [];
let lastWriteTime = 0; let lastWriteTime = 0;
return text => { return text => {
queue.push(text); queue.push({text, time: new Date().toLocaleString()});
debounce(flushQueue, 1e3); debounce(flushQueue, 1e3);
}; };
function flushQueue() { function flushQueue() {
chromeLocal.getValue('updateLog').then((lines = []) => { chromeLocal.getValue('updateLog').then((lines = []) => {
// our XHR timeout is 10 seconds const time = Date.now() - lastWriteTime > 11e3 ? queue[0].time + ' ' : '';
const time = performance.now() - lastWriteTime > 11e3
? new Date().toLocaleString() + '\t'
: '';
lines.splice(0, lines.length - 1000); lines.splice(0, lines.length - 1000);
lines.push(...queue.map(item => item ? time + item : '')); lines.push(time + queue[0].text);
lines.push(...queue.slice(1).map(item => item.text));
chromeLocal.setValue('updateLog', lines); chromeLocal.setValue('updateLog', lines);
lastWriteTime = performance.now(); lastWriteTime = Date.now();
queue = []; queue = [];
}); });
} }