mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Optimize purge of old live history data in the time window (#15153)
from https://github.com/home-assistant/frontend/pull/15112#discussion_r1083382923
This commit is contained in:
parent
f34d9c3d75
commit
3e14d825e3
@ -263,20 +263,27 @@ class HistoryStream {
|
|||||||
}
|
}
|
||||||
// Remove old history
|
// Remove old history
|
||||||
if (entityId in this.combinedHistory) {
|
if (entityId in this.combinedHistory) {
|
||||||
const entityHistory = newHistory[entityId];
|
const expiredStates = newHistory[entityId].filter(
|
||||||
while (entityHistory[0].lu < purgeBeforePythonTime) {
|
(state) => state.lu < purgeBeforePythonTime
|
||||||
if (entityHistory.length > 1) {
|
);
|
||||||
if (entityHistory[1].lu < purgeBeforePythonTime) {
|
if (!expiredStates.length) {
|
||||||
newHistory[entityId].shift();
|
continue;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
newHistory[entityId] = newHistory[entityId].filter(
|
||||||
|
(state) => state.lu >= purgeBeforePythonTime
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
newHistory[entityId].length &&
|
||||||
|
newHistory[entityId][0].lu === purgeBeforePythonTime
|
||||||
|
) {
|
||||||
|
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.
|
||||||
|
const lastExpiredState = expiredStates[expiredStates.length - 1];
|
||||||
|
lastExpiredState.lu = purgeBeforePythonTime;
|
||||||
|
newHistory[entityId].unshift(lastExpiredState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.combinedHistory = newHistory;
|
this.combinedHistory = newHistory;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user