Don't remove persistent data when clearing cache
This commit is contained in:
parent
67718d8fe4
commit
bb9cef55ea
|
@ -7,6 +7,7 @@
|
|||
|
||||
import SwiftUI
|
||||
import Pachyderm
|
||||
import CoreData
|
||||
|
||||
struct AdvancedPrefsView : View {
|
||||
@ObservedObject var preferences = Preferences.shared
|
||||
|
@ -49,9 +50,16 @@ struct AdvancedPrefsView : View {
|
|||
private func clearCache() {
|
||||
for account in LocalData.shared.accounts {
|
||||
let controller = MastodonController.getForAccount(account)
|
||||
let coordinator = controller.persistentContainer.persistentStoreCoordinator
|
||||
for store in coordinator.persistentStores {
|
||||
try! coordinator.destroyPersistentStore(at: store.url!, ofType: store.type, options: store.options)
|
||||
let container = controller.persistentContainer
|
||||
do {
|
||||
let statusesReq = NSBatchDeleteRequest(fetchRequest: StatusMO.fetchRequest())
|
||||
try container.viewContext.execute(statusesReq)
|
||||
let accountsReq = NSBatchDeleteRequest(fetchRequest: AccountMO.fetchRequest())
|
||||
try container.viewContext.execute(accountsReq)
|
||||
let relationshipsReq = NSBatchDeleteRequest(fetchRequest: RelationshipMO.fetchRequest())
|
||||
try container.viewContext.execute(relationshipsReq)
|
||||
} catch {
|
||||
Logging.general.error("Error while clearing Mastodon cache: \(String(describing: error), privacy: .public)")
|
||||
}
|
||||
}
|
||||
resetUI()
|
||||
|
|
Loading…
Reference in New Issue