Bug 844774 - Move old samples to last one. r=khuey

This commit is contained in:
Albert Crespell 2013-03-04 17:35:40 +01:00
Родитель 44c3412318
Коммит 67c5fb0930
1 изменённых файлов: 3 добавлений и 27 удалений

Просмотреть файл

@ -176,11 +176,13 @@ NetworkStatsDB.prototype = {
this._saveStats(txn, store, data);
return;
}
if (diff == 0) {
if (diff == 0 || diff < 0) {
// New element received before samplerate period.
// It means that device has been restarted (or clock / timezone change).
// Update element.
// If diff < 0, clock or timezone changed back. Place data in the last sample.
lastSample.rxBytes += rxDiff;
lastSample.txBytes += txDiff;
lastSample.rxTotalBytes = newSample.rxTotalBytes;
@ -190,13 +192,6 @@ NetworkStatsDB.prototype = {
}
let req = lastSampleCursor.update(lastSample);
}
if (diff < 0) {
// Clock or timezone changed back.
if (DEBUG) {
debug("This stat record is older than last one");
}
this._insertSample(txn, store, newSample, lastSample.timestamp);
}
},
_saveStats: function _saveStats(txn, store, networkStats) {
@ -214,25 +209,6 @@ NetworkStatsDB.prototype = {
}
},
_insertSample: function _insertSample(txn, store, sample, endTimestamp) {
let lowFilter = [sample.connectionType, sample.timestamp];
let upFilter = [sample.connectionType, endTimestamp];
let range = this.dbGlobal.IDBKeyRange.bound(lowFilter, upFilter, false, false);
let request = store.openCursor(range).onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
sample.rxBytes += cursor.value.rxBytes;
sample.txBytes += cursor.value.txBytes;
cursor.delete();
cursor.continue();
return;
}
this._saveStats(txn, store, sample);
}.bind(this);
},
_removeOldStats: function _removeOldStats(txn, store, connType, date) {
// Callback function to remove old items when new ones are added.
let filterDate = date - (SAMPLE_RATE * VALUES_MAX_LENGTH - 1);