fix:修复通知调试状态和重复命中问题
This commit is contained in:
@@ -22,6 +22,28 @@ const mapRow = (row) => ({
|
||||
errorMessage: row.error_message || '',
|
||||
})
|
||||
|
||||
const dedupeRecords = (rows = []) => {
|
||||
const bucket = new Map()
|
||||
|
||||
rows.forEach((row) => {
|
||||
const item = mapRow(row)
|
||||
const key = item.sourceId || item.id
|
||||
if (!bucket.has(key)) {
|
||||
bucket.set(key, item)
|
||||
return
|
||||
}
|
||||
|
||||
const existing = bucket.get(key)
|
||||
const existingScore = Number(Boolean(existing.transactionId)) + Number(existing.status === NOTIFICATION_DEBUG_STATUS.matched) + Number(Boolean(existing.ruleId))
|
||||
const nextScore = Number(Boolean(item.transactionId)) + Number(item.status === NOTIFICATION_DEBUG_STATUS.matched) + Number(Boolean(item.ruleId))
|
||||
if (nextScore > existingScore) {
|
||||
bucket.set(key, item)
|
||||
}
|
||||
})
|
||||
|
||||
return Array.from(bucket.values())
|
||||
}
|
||||
|
||||
const getLatestBySourceId = async (sourceId) => {
|
||||
if (!sourceId) return null
|
||||
const db = await getDb()
|
||||
@@ -150,5 +172,5 @@ export const fetchNotificationDebugRecords = async (options = {}) => {
|
||||
params,
|
||||
)
|
||||
|
||||
return (result?.values || []).map(mapRow)
|
||||
return dedupeRecords(result?.values || [])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user