From b5ae7df795ddcc2b4b1da02ec2bc8bdb99a063e1 Mon Sep 17 00:00:00 2001 From: Bryan Montz Date: Sat, 13 May 2023 09:17:41 -0500 Subject: [PATCH] add ability to change ProfileDatabase's storage URL --- damus/Nostr/ProfileDatabase.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/damus/Nostr/ProfileDatabase.swift b/damus/Nostr/ProfileDatabase.swift index 6da247bd..47490f6d 100644 --- a/damus/Nostr/ProfileDatabase.swift +++ b/damus/Nostr/ProfileDatabase.swift @@ -18,17 +18,19 @@ final class ProfileDatabase { private let entity_name = "PersistedProfile" private var persistent_container: NSPersistentContainer? private var background_context: NSManagedObjectContext? + private let cache_url: URL - init() { + init(cache_url: URL = ProfileDatabase.profile_cache_url) { + self.cache_url = cache_url set_up() } - private var profile_cache_url: URL { + private static var profile_cache_url: URL { (FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first?.appendingPathComponent("profiles"))! } private var persistent_store_description: NSPersistentStoreDescription { - let description = NSPersistentStoreDescription(url: profile_cache_url) + let description = NSPersistentStoreDescription(url: cache_url) description.type = NSSQLiteStoreType description.setOption(true as NSNumber, forKey: NSMigratePersistentStoresAutomaticallyOption) description.setOption(true as NSNumber, forKey: NSInferMappingModelAutomaticallyOption)