fix:修复通知调试状态和重复命中问题

This commit is contained in:
2026-03-13 10:34:30 +08:00
parent c8b30319e3
commit 2b2d56520f
6 changed files with 126 additions and 88 deletions

View File

@@ -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 || [])
}