fix(crypto-tail): 监控分时图推送节流与前端采样,避免1s内多条数据导致点过密

- 后端: price_change 推送节流,每策略 1s 内最多推送 1 次,其余靠定时 1.5s 推送补足
- 前端: 同周期内分时图追加点时至少间隔 1s 才追加,保证曲线连续且不过密
- 最新价等展示仍实时更新,仅图表序列做采样

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
WrBug
2026-02-25 20:01:29 +08:00
co-authored by Cursor
parent 377da4fff6
commit 0740abcf16
2 changed files with 17 additions and 4 deletions
@@ -97,6 +97,10 @@ class CryptoTailMonitorService(
private val strategyHistoryPeriod = ConcurrentHashMap<Long, Long>()
private val maxHistorySize = 300
/** price_change 推送节流:每策略最近一次推送时间,1s 内不重复推送 */
private val lastPriceChangePushTime = ConcurrentHashMap<Long, Long>()
private val priceChangePushThrottleMs = 1_000L
data class MonitorEntry(
val strategyId: Long,
val strategy: CryptoTailStrategy,
@@ -652,8 +656,13 @@ class CryptoTailMonitorService(
strategyPriceData[strategy.id!!] = newPriceData
val pushData = buildPushData(strategy, newPriceData)
addToHistoryAndPush(strategy.id!!, pushData)
val now = System.currentTimeMillis()
val last = lastPriceChangePushTime[strategy.id!!] ?: 0L
if (now - last >= priceChangePushThrottleMs) {
lastPriceChangePushTime[strategy.id!!] = now
val pushData = buildPushData(strategy, newPriceData)
addToHistoryAndPush(strategy.id!!, pushData)
}
}
}
+6 -2
View File
@@ -159,15 +159,19 @@ const CryptoTailMonitor: React.FC = () => {
setInitData(prev => prev ? { ...prev, periodStartUnix: pushPeriod } : null)
setPriceHistory([newPoint])
} else {
// 同周期:追加数据
// 记录首次数据时间(仅在中途进入且未切换过周期时记录)
// 同周期:追加数据(同周期内至少间隔 1s 才追加一点,避免 1s 内多条推送导致点过密)
setFirstDataTime(prev => {
if (prev == null) {
return newPoint.time
}
return prev
})
const minIntervalMs = 1_000
setPriceHistory(prev => {
const lastTime = prev.length > 0 ? prev[prev.length - 1].time : 0
if (prev.length > 0 && newPoint.time - lastTime < minIntervalMs) {
return prev
}
const maxPoints = 300
const newHistory = [...prev, newPoint]
return newHistory.slice(-maxPoints)