From 7923c172ff0440f53dcf9d900d4a85962f3b07b2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 21 Jan 2023 17:28:42 -1000 Subject: [PATCH] Revert "adjust" This reverts commit 6ba31da4a5a619a0da1bfbcfe18723de595e19aa. --- src/data/history.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/data/history.ts b/src/data/history.ts index cb5977778c..1f95af2552 100644 --- a/src/data/history.ts +++ b/src/data/history.ts @@ -264,18 +264,19 @@ class HistoryStream { // Remove old history if (entityId in this.combinedHistory) { const entityHistory = newHistory[entityId]; - const lastEntry = entityHistory[entityHistory.length - 1]; - const filtered = entityHistory.filter( - (ent) => ent.lu < purgeBeforePythonTime - ); - if (filtered.length === 0) { - filtered.push(lastEntry); + while (entityHistory[0].lu < purgeBeforePythonTime) { + if (entityHistory.length > 1) { + if (entityHistory[1].lu < purgeBeforePythonTime) { + newHistory[entityId].shift(); + continue; + } + } + // Update the first entry to the start time state + // as we need to preserve the start time state and + // only expire the rest of the history as it ages. + entityHistory[0].lu = purgeBeforePythonTime; + break; } - // Update the first entry to the start time state - // as we need to preserve the start time state and - // only expire the rest of the history as it ages. - filtered[0].lu = purgeBeforePythonTime; - newHistory[entityId] = filtered; } } this.combinedHistory = newHistory;