From 29ca4c29bb19fa2081dd9b8532cb77e4997c488c Mon Sep 17 00:00:00 2001 From: QIU Date: Fri, 14 Aug 2026 11:22:07 +0000 Subject: [PATCH] =?UTF-8?q?fix(data):=20=E6=8B=92=E7=BB=9D=20calculatePass?= =?UTF-8?q?es=20=E5=B9=B6=E5=8F=91=E8=B0=83=E7=94=A8=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: SatelliteRepo.calculatePasses() 在耗时计算期间如果被重复调用, 会启动多个协程同时遍历卫星列表,导致: 1. 重复的 SGP4 轨道计算(CPU/电池浪费) 2. passes MutableStateFlow 被多次更新,触发下游 UI 重组风暴 3. _isCalculating 标志被后续调用覆盖,可能提前置 false 修复: 在 _isCalculating.value = true 之前检查当前值,如果已在计算中则 直接 return,拒绝并发调用。 影响: 防止用户快速切换过滤条件、旋转屏幕等场景下的重复计算。 _isCalculating 现在是真正的互斥信号量(简化版,无等待队列)。 --- .../com/rtbishop/look4sat/core/data/repository/SatelliteRepo.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SatelliteRepo.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SatelliteRepo.kt index c5d1c143..c1a69693 100644 --- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SatelliteRepo.kt +++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SatelliteRepo.kt @@ -117,6 +117,8 @@ class SatelliteRepo( invertAosTimeWindow: Boolean, modes: List ) { + // 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