From 0740abcf16f85c617a493abe95770d42eb611233 Mon Sep 17 00:00:00 2001 From: WrBug Date: Wed, 25 Feb 2026 20:01:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(crypto-tail):=20=E7=9B=91=E6=8E=A7=E5=88=86?= =?UTF-8?q?=E6=97=B6=E5=9B=BE=E6=8E=A8=E9=80=81=E8=8A=82=E6=B5=81=E4=B8=8E?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E9=87=87=E6=A0=B7=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?1s=E5=86=85=E5=A4=9A=E6=9D=A1=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=82=B9=E8=BF=87=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 后端: price_change 推送节流,每策略 1s 内最多推送 1 次,其余靠定时 1.5s 推送补足 - 前端: 同周期内分时图追加点时至少间隔 1s 才追加,保证曲线连续且不过密 - 最新价等展示仍实时更新,仅图表序列做采样 Co-authored-by: Cursor --- .../service/cryptotail/CryptoTailMonitorService.kt | 13 +++++++++++-- frontend/src/pages/CryptoTailMonitor.tsx | 8 ++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailMonitorService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailMonitorService.kt index ed903cd..cece207 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailMonitorService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailMonitorService.kt @@ -97,6 +97,10 @@ class CryptoTailMonitorService( private val strategyHistoryPeriod = ConcurrentHashMap() private val maxHistorySize = 300 + /** price_change 推送节流:每策略最近一次推送时间,1s 内不重复推送 */ + private val lastPriceChangePushTime = ConcurrentHashMap() + 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) + } } } diff --git a/frontend/src/pages/CryptoTailMonitor.tsx b/frontend/src/pages/CryptoTailMonitor.tsx index ccd5916..69ad8f2 100644 --- a/frontend/src/pages/CryptoTailMonitor.tsx +++ b/frontend/src/pages/CryptoTailMonitor.tsx @@ -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)