Просмотр исходного кода

parallelize meal/iob calculation

polscm32 aka Marvout 1 год назад
Родитель
Сommit
dbd40534bb
1 измененных файлов с 8 добавлено и 10 удалено
  1. 8 10
      FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

+ 8 - 10
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -273,10 +273,6 @@ final class OpenAPS {
     ) async throws -> Determination? {
         debug(.openAPS, "Start determineBasal")
 
-        // clock
-        let dateFormatted = OpenAPS.dateFormatter.string(from: clock)
-        let dateFormattedAsString = "\"\(dateFormatted)\""
-
         // temp_basal
         let tempBasal = currentTemp.rawJSON
 
@@ -314,24 +310,26 @@ final class OpenAPS {
             preferencesAsync
         )
 
-        // Meal
-        let meal = try await self.meal(
+        // Parallelize Meal and IOB calculations
+        async let calculateMeal = self.meal(
             pumphistory: pumpHistoryJSON,
             profile: profile,
             basalProfile: basalProfile,
-            clock: dateFormattedAsString,
+            clock: clock,
             carbs: carbsAsJSON,
             glucose: glucoseAsJSON
         )
 
-        // IOB
-        let iob = try await self.iob(
+        async let calculateIOB = self.iob(
             pumphistory: pumpHistoryJSON,
             profile: profile,
-            clock: dateFormattedAsString,
+            clock: clock,
             autosens: autosens.isEmpty ? .null : autosens
         )
 
+        // Await the meal and IOB results
+        let (meal, iob) = try await (calculateMeal, calculateIOB)
+
         // TODO: refactor this to core data
         if !simulation {
             storage.save(iob, as: Monitor.iob)