polscm32 пре 1 година
родитељ
комит
700ee90aed
1 измењених фајлова са 9 додато и 9 уклоњено
  1. 9 9
      FreeAPS/Sources/Services/HealthKit/HealthKitManager.swift

+ 9 - 9
FreeAPS/Sources/Services/HealthKit/HealthKitManager.swift

@@ -344,20 +344,20 @@ final class BaseHealthKitManager: HealthKitManager, Injectable {
             batchSize: 50
         )
 
-        // Ensure that the fetched results are of the expected type
-        guard let existingTempBasalEntries = results as? [PumpEventStored] else { return }
-
-        // Create a mapping from timestamps to indices for quick access to existing entries
-        let existingEntriesByTimestamp = Dictionary(
-            uniqueKeysWithValues: existingTempBasalEntries.enumerated()
-                .map { ($0.element.timestamp, $0.offset) }
-        )
-
         // Initialize an array to hold the HealthKit samples to be uploaded
         var insulinSamples: [HKQuantitySample] = []
 
         // Perform the data processing on the background context
         await backgroundContext.perform {
+            // Ensure that the fetched results are of the expected type
+            guard let existingTempBasalEntries = results as? [PumpEventStored] else { return }
+
+            // Create a mapping from timestamps to indices for quick access to existing entries
+            let existingEntriesByTimestamp = Dictionary(
+                uniqueKeysWithValues: existingTempBasalEntries.enumerated()
+                    .map { ($0.element.timestamp, $0.offset) }
+            )
+
             for event in insulin {
                 switch event.type {
                 case .bolus: