Fix live logbook starting empty (#12833)

This commit is contained in:
J. Nick Koston 2022-05-30 19:03:51 -10:00 committed by GitHub
parent ceda911670
commit 077fa3f6b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -310,7 +310,7 @@ export class HaLogbook extends LitElement {
// Put newest ones on top. Reverse works in-place so // Put newest ones on top. Reverse works in-place so
// make a copy first. // make a copy first.
const newEntries = [...streamMessage.events].reverse(); const newEntries = [...streamMessage.events].reverse();
if (!this._logbookEntries) { if (!this._logbookEntries || !this._logbookEntries.length) {
this._logbookEntries = newEntries; this._logbookEntries = newEntries;
return; return;
} }
@ -320,14 +320,16 @@ export class HaLogbook extends LitElement {
return; return;
} }
const nonExpiredRecords = this._nonExpiredRecords(purgeBeforePythonTime); const nonExpiredRecords = this._nonExpiredRecords(purgeBeforePythonTime);
this._logbookEntries = this._logbookEntries = !nonExpiredRecords.length
newEntries[0].when >= this._logbookEntries[0].when ? // All existing entries expired
? // The new records are newer than the old records newEntries
// append the old records to the end of the new records : newEntries[0].when >= nonExpiredRecords[0].when
newEntries.concat(nonExpiredRecords) ? // The new records are newer than the old records
: // The new records are older than the old records // append the old records to the end of the new records
// append the new records to the end of the old records newEntries.concat(nonExpiredRecords)
nonExpiredRecords.concat(newEntries); : // The new records are older than the old records
// append the new records to the end of the old records
nonExpiredRecords.concat(newEntries);
}; };
private _updateTraceContexts = throttle(async () => { private _updateTraceContexts = throttle(async () => {