forked from shadowfacts/Tusker
Don't remove persistent data when clearing cache
This commit is contained in:
parent
67718d8fe4
commit
bb9cef55ea
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
|
import CoreData
|
||||||
|
|
||||||
struct AdvancedPrefsView : View {
|
struct AdvancedPrefsView : View {
|
||||||
@ObservedObject var preferences = Preferences.shared
|
@ObservedObject var preferences = Preferences.shared
|
||||||
|
@ -49,9 +50,16 @@ struct AdvancedPrefsView : View {
|
||||||
private func clearCache() {
|
private func clearCache() {
|
||||||
for account in LocalData.shared.accounts {
|
for account in LocalData.shared.accounts {
|
||||||
let controller = MastodonController.getForAccount(account)
|
let controller = MastodonController.getForAccount(account)
|
||||||
let coordinator = controller.persistentContainer.persistentStoreCoordinator
|
let container = controller.persistentContainer
|
||||||
for store in coordinator.persistentStores {
|
do {
|
||||||
try! coordinator.destroyPersistentStore(at: store.url!, ofType: store.type, options: store.options)
|
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()
|
resetUI()
|
||||||
|
|
Loading…
Reference in New Issue