From 6df7cf8a80073b37e06ea301ea83058559c52156 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Wed, 11 Oct 2023 15:38:31 +0200 Subject: [PATCH] Don't use core data in memory (for now) --- MastodonIntent/Handler/SendPostIntentHandler.swift | 2 +- MastodonSDK/Sources/CoreDataStack/CoreDataStack.swift | 2 +- MastodonSDK/Sources/MastodonCore/AppContext.swift | 11 +++-------- .../MastodonCore/AuthenticationServiceProvider.swift | 2 ++ 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/MastodonIntent/Handler/SendPostIntentHandler.swift b/MastodonIntent/Handler/SendPostIntentHandler.swift index af56ad523..b457b1c91 100644 --- a/MastodonIntent/Handler/SendPostIntentHandler.swift +++ b/MastodonIntent/Handler/SendPostIntentHandler.swift @@ -17,7 +17,7 @@ final class SendPostIntentHandler: NSObject { var disposeBag = Set() - let coreDataStack = CoreDataStack(isInMemory: true) + let coreDataStack = CoreDataStack() lazy var managedObjectContext = coreDataStack.persistentContainer.viewContext lazy var api: APIService = { let backgroundManagedObjectContext = coreDataStack.newTaskContext() diff --git a/MastodonSDK/Sources/CoreDataStack/CoreDataStack.swift b/MastodonSDK/Sources/CoreDataStack/CoreDataStack.swift index 720e5df85..3a30e9443 100644 --- a/MastodonSDK/Sources/CoreDataStack/CoreDataStack.swift +++ b/MastodonSDK/Sources/CoreDataStack/CoreDataStack.swift @@ -20,7 +20,7 @@ public final class CoreDataStack { self.storeDescriptions = storeDescriptions } - public convenience init(databaseName: String = "shared", isInMemory: Bool) { + public convenience init(databaseName: String = "shared", isInMemory: Bool = false) { let storeURL = URL.storeURL(for: AppName.groupID, databaseName: databaseName) let storeDescription: NSPersistentStoreDescription if isInMemory { diff --git a/MastodonSDK/Sources/MastodonCore/AppContext.swift b/MastodonSDK/Sources/MastodonCore/AppContext.swift index b8cf3b259..c1e8933ee 100644 --- a/MastodonSDK/Sources/MastodonCore/AppContext.swift +++ b/MastodonSDK/Sources/MastodonCore/AppContext.swift @@ -48,21 +48,16 @@ public class AppContext: ObservableObject { public init() { let authProvider = AuthenticationServiceProvider.shared - let _coreDataStack: CoreDataStack + let _coreDataStack = CoreDataStack() if authProvider.authenticationMigrationRequired { - _coreDataStack = CoreDataStack(isInMemory: false) authProvider.migrateLegacyAuthentications( in: _coreDataStack.persistentContainer.viewContext ) - } else { - _coreDataStack = CoreDataStack(isInMemory: true) } - + let _managedObjectContext = _coreDataStack.persistentContainer.viewContext - _coreDataStack.persistentContainer.persistentStoreDescriptions.forEach { - $0.url = URL(fileURLWithPath: "/dev/null") - } let _backgroundManagedObjectContext = _coreDataStack.persistentContainer.newBackgroundContext() + coreDataStack = _coreDataStack managedObjectContext = _managedObjectContext backgroundManagedObjectContext = _backgroundManagedObjectContext diff --git a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift index f3cd504a0..1d8b2d6cc 100644 --- a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift +++ b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift @@ -89,6 +89,8 @@ public extension AuthenticationServiceProvider { if migratedAuthentications.count != legacyAuthentications.count { logger.log(level: .default, "Not all account authentications could be migrated.") + } else { + logger.log(level: .default, "All account authentications were successful.") } self.authentications = migratedAuthentications