feat: 优化跟单轮询自动启动/停止逻辑

- addLeader 时自动启动轮询任务(如果还没有运行)
- removeLeader 时自动停止轮询任务(如果没有需要监听的 Leader)
- 确保轮询任务根据跟单状态动态调整,避免不必要的资源消耗
This commit is contained in:
WrBug
2025-12-03 06:25:28 +08:00
parent 56caba963c
commit 8bac55b943
@@ -78,6 +78,9 @@ class CopyTradingPollingService(
cachedTradeIds[leaderId] = mutableSetOf()
// 首次轮询标志,用于缓存数据而不处理
isFirstPoll[leaderId] = true
// 如果轮询任务没有运行,启动它
startPolling()
}
/**
@@ -87,6 +90,11 @@ class CopyTradingPollingService(
monitoredLeaders.remove(leaderId)
cachedTradeIds.remove(leaderId)
isFirstPoll.remove(leaderId)
// 如果没有需要监听的Leader了,停止轮询任务
if (monitoredLeaders.isEmpty()) {
stopPolling()
}
}
/**