fix(dees-chart-log): avoid duplicate log entries, optimize incremental updates, enforce maxEntries, and respect filters when writing logs
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@design.estate/dees-catalog',
|
||||
version: '3.43.1',
|
||||
version: '3.43.2',
|
||||
description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
|
||||
}
|
||||
|
||||
@@ -385,11 +385,23 @@ export class DeesChartLog extends DeesElement {
|
||||
this.domtoolsInstance = await this.domtoolsPromise;
|
||||
await this.initializeTerminal();
|
||||
|
||||
// Process any initial log entries
|
||||
if (this.logEntries.length > 0) {
|
||||
// initializeTerminal() already replayed logBuffer (from addLog/updateLog).
|
||||
// Now handle logEntries set via property binding before terminal was ready.
|
||||
if (this.logEntries.length > 0 && this.logBuffer.length === 0) {
|
||||
this.logBuffer = [...this.logEntries];
|
||||
for (const entry of this.logEntries) {
|
||||
this.updateMetrics(entry.level);
|
||||
this.writeLogEntry(entry);
|
||||
}
|
||||
} else if (this.logEntries.length > 0 && this.logBuffer.length > 0) {
|
||||
const bufferSet = new Set(this.logBuffer.map(e => `${e.timestamp}|${e.message}`));
|
||||
for (const entry of this.logEntries) {
|
||||
if (!bufferSet.has(`${entry.timestamp}|${entry.message}`)) {
|
||||
this.logBuffer.push(entry);
|
||||
this.updateMetrics(entry.level);
|
||||
this.writeLogEntry(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,7 +467,46 @@ export class DeesChartLog extends DeesElement {
|
||||
public updated(changedProperties: Map<string, any>) {
|
||||
super.updated(changedProperties);
|
||||
if (changedProperties.has('logEntries') && this.terminalReady && this.logEntries.length > 0) {
|
||||
this.logBuffer = [...this.logEntries];
|
||||
const oldEntries: ILogEntry[] = changedProperties.get('logEntries') || [];
|
||||
const newEntries = this.logEntries;
|
||||
|
||||
// Same content? Skip entirely.
|
||||
if (
|
||||
oldEntries.length === newEntries.length &&
|
||||
oldEntries.length > 0 &&
|
||||
oldEntries[oldEntries.length - 1].timestamp === newEntries[newEntries.length - 1].timestamp &&
|
||||
oldEntries[oldEntries.length - 1].message === newEntries[newEntries.length - 1].message
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Append-only? Write only the new tail entries incrementally.
|
||||
if (
|
||||
newEntries.length > oldEntries.length &&
|
||||
oldEntries.length > 0 &&
|
||||
oldEntries[oldEntries.length - 1].timestamp === newEntries[oldEntries.length - 1].timestamp &&
|
||||
oldEntries[oldEntries.length - 1].message === newEntries[oldEntries.length - 1].message
|
||||
) {
|
||||
const tailEntries = newEntries.slice(oldEntries.length);
|
||||
for (const entry of tailEntries) {
|
||||
this.logBuffer.push(entry);
|
||||
this.updateMetrics(entry.level);
|
||||
|
||||
// Enforce maxEntries
|
||||
if (this.logBuffer.length > this.maxEntries) {
|
||||
this.logBuffer.shift();
|
||||
}
|
||||
|
||||
// Respect filter mode
|
||||
if (!this.filterMode || !this.searchQuery || this.entryMatchesFilter(entry)) {
|
||||
this.writeLogEntry(entry);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Different content — full re-render
|
||||
this.logBuffer = [...newEntries];
|
||||
this.reRenderFilteredLogs();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user