|
|
@@ -85,9 +85,6 @@ final class BaseGarminManager: NSObject, GarminManager, Injectable, @unchecked S
|
|
|
/// Enable/disable general Garmin debug logging (connections, settings, throttling, etc.)
|
|
|
private let debugGarmin = true // Set to false to disable verbose Garmin logging
|
|
|
|
|
|
- /// Track when we last sent to determination subject to prevent duplicate cached data
|
|
|
- private var lastDeterminationSendTime: Date?
|
|
|
-
|
|
|
/// Enable simulated Garmin device for Xcode Simulator testing
|
|
|
/// When true, creates a fake Garmin device so you can test the workflow in Simulator
|
|
|
#if targetEnvironment(simulator)
|
|
|
@@ -374,29 +371,12 @@ final class BaseGarminManager: NSObject, GarminManager, Injectable, @unchecked S
|
|
|
do {
|
|
|
let watchState = try await self.setupGarminWatchState(triggeredBy: "Determination")
|
|
|
|
|
|
- // Check if preparation was skipped due to unchanged data
|
|
|
- self.hashLock.lock()
|
|
|
- let currentHash = self.lastPreparedDataHash
|
|
|
- let wasCached = (watchState == self.lastPreparedWatchState)
|
|
|
- self.hashLock.unlock()
|
|
|
-
|
|
|
- // If data came from cache AND we recently sent it to the subject, skip
|
|
|
- if wasCached {
|
|
|
- if let lastSend = self.lastDeterminationSendTime,
|
|
|
- Date().timeIntervalSince(lastSend) < 3
|
|
|
- {
|
|
|
- self
|
|
|
- .debugGarmin(
|
|
|
- "[\(self.formatTimeForLog())] Skipping duplicate determination trigger - already in pipeline (hash: \(currentHash ?? 0))"
|
|
|
- )
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
let watchStateData = try JSONEncoder().encode(watchState)
|
|
|
self.currentSendTrigger = "Determination"
|
|
|
- self.lastDeterminationSendTime = Date() // Track when we sent to subject
|
|
|
- // Send to subject for additional 2s debouncing before Bluetooth transmission
|
|
|
+
|
|
|
+ // Send to subject for 2s debouncing before Bluetooth transmission
|
|
|
+ // Hash-based caching in setupGarminWatchState prevents unnecessary work
|
|
|
+ // No additional blocking needed - debounce handles deduplication
|
|
|
self.determinationSubject.send(watchStateData)
|
|
|
} catch {
|
|
|
debug(
|