mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +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
|
||||
if (entityId in this.combinedHistory) {
|
||||
const entityHistory = newHistory[entityId];
|
||||
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;
|
||||
const expiredStates = newHistory[entityId].filter(
|
||||
(state) => state.lu < purgeBeforePythonTime
|
||||
);
|
||||
if (!expiredStates.length) {
|
||||
continue;
|
||||
}
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user