Skip to content

Commit

Permalink
Avoid double saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-b-m committed Jun 7, 2023
1 parent f574da1 commit ce6081e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
2 changes: 0 additions & 2 deletions FreeAPS/Sources/APS/Storage/GlucoseStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ final class BaseGlucoseStorage: GlucoseStorage, Injectable {
if bg_ != 0 {
self.coredataContext.perform {
let dataForForStats = Readings(context: self.coredataContext)

dataForForStats.date = bgDate
dataForForStats.glucose = Int16(bg_)
dataForForStats.id = id

try? self.coredataContext.save()
}
}
Expand Down
6 changes: 3 additions & 3 deletions FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ extension Bolus {

func setupInsulinRequired() {
DispatchQueue.main.async {
//Manual Bolus recommondentations screen after a carb entry (normally) yields a higher amount than the insulinReq amount computed for SMBs (auto boluses). Carbs combined with a manual bolus uses the Eventual BG for glucose prediction, whereas the insulinReg for SMBs and for manual boluses not combined with a carb entry uses the minPredBG for glucose prediction (typically lower than Eventual BG).
// Manual Bolus recommondentations screen after a carb entry (normally) yields a higher amount than the insulinReq amount computed for SMBs (auto boluses). Carbs combined with a manual bolus uses the Eventual BG for glucose prediction, whereas the insulinReg for SMBs and for manual boluses not combined with a carb entry uses the minPredBG for glucose prediction (typically lower than Eventual BG).

if self.manual {
self.insulinRequired = self.provider.suggestion?.insulinForManualBolus ?? 0

if self.settingsManager.settings.insulinReqPercentage != 100 {
self.insulinRecommended = self
.insulinRequired * (self.settingsManager.settings.insulinReqPercentage / 100)
Expand Down
12 changes: 1 addition & 11 deletions FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ extension DataTable {
let fetchRequest: NSFetchRequest<NSFetchRequestResult>
fetchRequest = NSFetchRequest(entityName: "Readings")
fetchRequest.predicate = NSPredicate(format: "id == %@", id)

let deleteRequest = NSBatchDeleteRequest(
fetchRequest: fetchRequest
)
Expand All @@ -158,7 +157,7 @@ extension DataTable {
} catch {
// To do: handle any thrown errors.
}
try? coredataContext.save()
// try? coredataContext.save()
}

func addManualGlucose() {
Expand All @@ -179,15 +178,6 @@ extension DataTable {
)
provider.glucoseStorage.storeGlucose([saveToJSON])
debug(.default, "Manual Glucose saved to glucose.json")

coredataContext.perform {
let saveToCoreData = Readings(context: self.coredataContext)
saveToCoreData.date = now
saveToCoreData.glucose = Int16(Int(glucose))
saveToCoreData.id = id
try? self.coredataContext.save()
debug(.default, "Manual Glucose saved to CoreData")
}
}
}
}
Expand Down

0 comments on commit ce6081e

Please sign in to comment.