This commit is contained in:
J. Nick Koston 2023-01-21 17:06:23 -10:00
parent e1d17f3d3a
commit 690e2a3aa9

View File

@ -238,7 +238,6 @@ class HistoryStream {
newHistory[entityId] = []; newHistory[entityId] = [];
} }
for (const entityId of Object.keys(newHistory)) { for (const entityId of Object.keys(newHistory)) {
let purgeOld = entityId in this.combinedHistory;
if ( if (
entityId in this.combinedHistory && entityId in this.combinedHistory &&
entityId in streamMessage.states entityId in streamMessage.states
@ -257,14 +256,13 @@ class HistoryStream {
(a, b) => a.lu - b.lu (a, b) => a.lu - b.lu
); );
} }
purgeOld = true;
} else if (entityId in this.combinedHistory) { } else if (entityId in this.combinedHistory) {
newHistory[entityId] = this.combinedHistory[entityId]; newHistory[entityId] = this.combinedHistory[entityId];
purgeOld = true;
} else { } else {
newHistory[entityId] = streamMessage.states[entityId]; newHistory[entityId] = streamMessage.states[entityId];
} }
if (purgeOld) { // Remove old history
if (entityId in this.combinedHistory) {
const entityHistory = newHistory[entityId]; const entityHistory = newHistory[entityId];
while (entityHistory[0].lu < purgeBeforePythonTime) { while (entityHistory[0].lu < purgeBeforePythonTime) {
if (entityHistory.length > 1) { if (entityHistory.length > 1) {