fix(data): 拒绝 calculatePasses 并发调用防止重复计算
根因: SatelliteRepo.calculatePasses() 在耗时计算期间如果被重复调用, 会启动多个协程同时遍历卫星列表,导致: 1. 重复的 SGP4 轨道计算(CPU/电池浪费) 2. passes MutableStateFlow 被多次更新,触发下游 UI 重组风暴 3. _isCalculating 标志被后续调用覆盖,可能提前置 false 修复: 在 _isCalculating.value = true 之前检查当前值,如果已在计算中则 直接 return,拒绝并发调用。 影响: 防止用户快速切换过滤条件、旋转屏幕等场景下的重复计算。 _isCalculating 现在是真正的互斥信号量(简化版,无等待队列)。
This commit is contained in:
1 parent
82c8112575
commit
29ca4c29bb
1 file changed
+2
@@ -117,6 +117,8 @@ class SatelliteRepo(
|
||||
invertAosTimeWindow: Boolean,
|
||||
modes: List<String>
|
||||
) {
|
||||
// Reject concurrent calls to prevent duplicate calculations
|
||||
if (_isCalculating.value) return
|
||||
_isCalculating.value = true
|
||||
// Normalize to the start of the current minute so that coarse 60-second stepping
|
||||
// in getLeoPass always begins from the same phase, producing stable AOS/LOS times
|
||||
|
||||
Reference in new issue
Block a user