Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions LoopCore/PersistenceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ extension PersistenceController {
return self.init(directoryURL: directoryURL.appendingPathComponent("com.loopkit.LoopKit", isDirectory: true), isReadOnly: isReadOnly)
}

public class func controllerInLocalDirectory() -> PersistenceController {
public class func controllerInLocalDirectory(named name: String = "com.loopkit.LoopKit") -> PersistenceController {
guard let directoryURL = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) else {
fatalError("Could not access the document directory of the current process")
}

let isReadOnly = Bundle.main.isAppExtension

return self.init(directoryURL: directoryURL.appendingPathComponent("com.loopkit.LoopKit"), isReadOnly: isReadOnly)
return self.init(directoryURL: directoryURL.appendingPathComponent(name), isReadOnly: isReadOnly)
}
}
11 changes: 9 additions & 2 deletions WatchApp Extension/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,17 @@ class LoopDataManager {
loopSettings: LoopSettings(),
scheduleOverride: nil
)


// Give GlucoseStore its own Core Data stack rather than sharing `cacheStore` with
// CarbStore. GlucoseStore drives its context exclusively with the async
// `context.perform` API, while CarbStore uses `performAndWait`. Sharing one serial
// context between the two mixes those concurrency models and can race, producing a
// torn read of a freshly-inserted CachedGlucoseObject (a nil required attribute).
// A dedicated context removes that cross-store contention.
let glucoseCacheStore = PersistenceController.controllerInLocalDirectory(named: "com.loopkit.LoopKit.Glucose")
Task {
glucoseStore = await GlucoseStore(
cacheStore: cacheStore,
cacheStore: glucoseCacheStore,
cacheLength: .hours(4)
)
}
Expand Down