fix(crypto-tail): 监控分时图推送节流与前端采样,避免1s内多条数据导致点过密
- 后端: price_change 推送节流,每策略 1s 内最多推送 1 次,其余靠定时 1.5s 推送补足 - 前端: 同周期内分时图追加点时至少间隔 1s 才追加,保证曲线连续且不过密 - 最新价等展示仍实时更新,仅图表序列做采样 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+11
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user