Don't use core data in memory (for now)

This commit is contained in:
Nathan Mattes 2023-10-11 15:38:31 +02:00
parent 544869c9f9
commit 6df7cf8a80
4 changed files with 7 additions and 10 deletions

View File

@ -17,7 +17,7 @@ final class SendPostIntentHandler: NSObject {
var disposeBag = Set<AnyCancellable>()
let coreDataStack = CoreDataStack(isInMemory: true)
let coreDataStack = CoreDataStack()
lazy var managedObjectContext = coreDataStack.persistentContainer.viewContext
lazy var api: APIService = {
let backgroundManagedObjectContext = coreDataStack.newTaskContext()

View File

@ -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 {

View File

@ -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

View File

@ -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