Fix boundary bugs, route side effects through MoodLogger, add data listeners
- Fix ExtensionDataProvider <= boundary to < in date queries (prevented cross-day leaks) - Replace force-unwraps with guards and add error logging in DataControllerGET and ExtensionDataProvider - Route DayViewViewModel update/delete through MoodLogger.shared (was duplicating side effects) - Add data listeners to InsightsViewModel and YearViewModel for cross-tab refresh - Add HealthKitManager.deleteMood(for:) for single-date cleanup - Add SharedModelContainer.isUsingInMemoryFallback flag with critical logging - Add analytics events: entryDeleted, allDataCleared, duplicatesRemoved, storageFallbackActivated Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,10 @@ enum SharedModelContainerError: LocalizedError {
|
||||
enum SharedModelContainer {
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "com.tt.feels", category: "SharedModelContainer")
|
||||
|
||||
/// Indicates whether the app is running with in-memory storage due to a failed App Group container.
|
||||
/// When `true`, all data will be lost on app restart.
|
||||
static private(set) var isUsingInMemoryFallback = false
|
||||
|
||||
/// Creates a ModelContainer with the appropriate configuration for app group sharing
|
||||
/// - Parameter useCloudKit: Whether to enable CloudKit sync (defaults to true)
|
||||
/// - Returns: Configured ModelContainer
|
||||
@@ -68,6 +72,11 @@ enum SharedModelContainer {
|
||||
return try create(useCloudKit: useCloudKit)
|
||||
} catch {
|
||||
logger.warning("Falling back to in-memory storage due to: \(error.localizedDescription)")
|
||||
logger.critical("App is using in-memory storage — all mood data will be lost on restart. App Group container failed: \(error.localizedDescription)")
|
||||
#if DEBUG
|
||||
assertionFailure("SharedModelContainer fell back to in-memory storage. App Group container is unavailable: \(error.localizedDescription)")
|
||||
#endif
|
||||
isUsingInMemoryFallback = true
|
||||
// Fall back to in-memory storage
|
||||
let schema = Schema([MoodEntryModel.self])
|
||||
let config = ModelConfiguration(schema: schema, isStoredInMemoryOnly: true)
|
||||
|
||||
Reference in New Issue
Block a user