fix(dashboard): deduplicate realtime log replay
This commit is contained in:
1 parent
e003b0d8b2
commit
89f7376b1b
4 files changed
+49
-9
No files matched your search
@@ -31,10 +31,19 @@ function boundedAppend(
|
||||
entry: ConsoleEntry,
|
||||
capacity: number,
|
||||
): readonly ConsoleEntry[] {
|
||||
if (entries.some(({ id }) => id === entry.id)) return entries;
|
||||
if (entries.some((candidate) => isSameEntry(candidate, entry))) return entries;
|
||||
return [...entries, entry].slice(-capacity);
|
||||
}
|
||||
|
||||
function isSameEntry(left: ConsoleEntry, right: ConsoleEntry): boolean {
|
||||
return left.id === right.id || (
|
||||
left.occurredAt === right.occurredAt &&
|
||||
left.level === right.level &&
|
||||
left.message === right.message &&
|
||||
searchableData(left.data) === searchableData(right.data)
|
||||
);
|
||||
}
|
||||
|
||||
export function createLiveConsoleState(capacity = 500): LiveConsoleState {
|
||||
if (!Number.isInteger(capacity) || capacity <= 0) {
|
||||
throw new RangeError('capacity must be a positive integer');
|
||||
@@ -57,8 +66,8 @@ export function reduceLiveConsoleState(
|
||||
switch (action.type) {
|
||||
case 'append': {
|
||||
if (
|
||||
state.entries.some(({ id }) => id === action.entry.id) ||
|
||||
state.pendingEntries.some(({ id }) => id === action.entry.id)
|
||||
state.entries.some((entry) => isSameEntry(entry, action.entry)) ||
|
||||
state.pendingEntries.some((entry) => isSameEntry(entry, action.entry))
|
||||
) return state;
|
||||
return state.isPaused
|
||||
? { ...state, pendingEntries: boundedAppend(state.pendingEntries, action.entry, state.capacity) }
|
||||
|
||||
Reference in new issue
Block a user