优化
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
const VOLATILE_SNAPSHOT_FIELDS = new Set([
|
||||
'requestHash', 'version', 'updatedAt', 'operatorId', 'operatorName', 'occurredAt',
|
||||
])
|
||||
|
||||
function stableValue(value) {
|
||||
if (Array.isArray(value)) return value.map(stableValue)
|
||||
if (!value || typeof value !== 'object') return value
|
||||
return Object.fromEntries(Object.entries(value)
|
||||
.filter(([key]) => !VOLATILE_SNAPSHOT_FIELDS.has(key))
|
||||
.sort(([left], [right]) => left.localeCompare(right))
|
||||
.map(([key, nested]) => [key, stableValue(nested)]))
|
||||
}
|
||||
|
||||
function snapshot(value) {
|
||||
if (value == null || value === '') return null
|
||||
try { return stableValue(typeof value === 'string' ? JSON.parse(value) : value) } catch { return value }
|
||||
}
|
||||
|
||||
function sameSnapshot(left, right) {
|
||||
return JSON.stringify(snapshot(left)) === JSON.stringify(snapshot(right))
|
||||
}
|
||||
|
||||
export function isPureStatusNoop(history) {
|
||||
if (history?.actionType !== 'STATUS_UPDATE') return false
|
||||
if ((history?.fromStatus ?? null) !== (history?.toStatus ?? null)) return false
|
||||
return sameSnapshot(history?.beforeSnapshot, history?.afterSnapshot)
|
||||
}
|
||||
|
||||
function stableEventKey(history) {
|
||||
if (history?.operationId) return `operation:${history.operationId}`
|
||||
if (history?.eventId) return `event:${history.eventId}`
|
||||
if (history?.historyId) return `history:${history.historyId}`
|
||||
return null
|
||||
}
|
||||
|
||||
export function visibleLoadingHistories(histories) {
|
||||
const seen = new Set()
|
||||
return (Array.isArray(histories) ? histories : []).filter((history) => {
|
||||
if (isPureStatusNoop(history)) return false
|
||||
const key = stableEventKey(history)
|
||||
if (!key) return true
|
||||
if (seen.has(key)) return false
|
||||
seen.add(key)
|
||||
return true
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user