Add cache reset button to Advanced Preferences
This commit is contained in:
parent
0582812563
commit
35a510e8ed
|
@ -30,6 +30,10 @@ class MastodonController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func resetAll() {
|
||||||
|
all = [:]
|
||||||
|
}
|
||||||
|
|
||||||
private let transient: Bool
|
private let transient: Bool
|
||||||
private(set) lazy var persistentContainer = MastodonCachePersistentStore(for: accountInfo, transient: transient)
|
private(set) lazy var persistentContainer = MastodonCachePersistentStore(for: accountInfo, transient: transient)
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,9 @@ class ConversationTableViewController: EnhancedTableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
guard let persistentContainer = mastodonController?.persistentContainer else { return }
|
||||||
for (id, _) in statuses {
|
for (id, _) in statuses {
|
||||||
mastodonController.persistentContainer.status(for: id)?.decrementReferenceCount()
|
persistentContainer.status(for: id)?.decrementReferenceCount()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ struct AdvancedPrefsView : View {
|
||||||
List {
|
List {
|
||||||
formattingSection
|
formattingSection
|
||||||
automationSection
|
automationSection
|
||||||
|
cachingSection
|
||||||
}.listStyle(GroupedListStyle())
|
}.listStyle(GroupedListStyle())
|
||||||
.navigationBarTitle(Text("Advanced"))
|
.navigationBarTitle(Text("Advanced"))
|
||||||
}
|
}
|
||||||
|
@ -41,6 +42,27 @@ struct AdvancedPrefsView : View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cachingSection: some View {
|
||||||
|
Section(header: Text("CACHING")) {
|
||||||
|
Button(action: clearCache) {
|
||||||
|
Text("Clear Cache")
|
||||||
|
}.foregroundColor(.red)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MastodonController.resetAll()
|
||||||
|
let mostRecent = LocalData.shared.getMostRecentAccount()!
|
||||||
|
NotificationCenter.default.post(name: .activateAccount, object: nil, userInfo: ["account": mostRecent])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension StatusContentType {
|
extension StatusContentType {
|
||||||
|
|
|
@ -62,8 +62,7 @@ class ProfileTableViewController: EnhancedTableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
if let id = accountID {
|
if let id = accountID, let container = mastodonController?.persistentContainer {
|
||||||
let container = mastodonController.persistentContainer
|
|
||||||
container.backgroundContext.perform {
|
container.backgroundContext.perform {
|
||||||
container.account(for: id, in: container.backgroundContext)?.decrementReferenceCount()
|
container.account(for: id, in: container.backgroundContext)?.decrementReferenceCount()
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,7 @@ class StatusActionAccountListTableViewController: EnhancedTableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
if let accountIDs = self.accountIDs {
|
if let accountIDs = self.accountIDs, let container = mastodonController?.persistentContainer {
|
||||||
let container = self.mastodonController.persistentContainer
|
|
||||||
container.backgroundContext.perform {
|
container.backgroundContext.perform {
|
||||||
for id in accountIDs {
|
for id in accountIDs {
|
||||||
container.account(for: id, in: container.backgroundContext)?.decrementReferenceCount()
|
container.account(for: id, in: container.backgroundContext)?.decrementReferenceCount()
|
||||||
|
|
|
@ -39,12 +39,13 @@ class TimelineTableViewController: EnhancedTableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
guard let persistentContainer = mastodonController?.persistentContainer else { return }
|
||||||
// decrement reference counts of any statuses we still have
|
// decrement reference counts of any statuses we still have
|
||||||
// if the app is currently being quit, this will not affect the persisted data because
|
// if the app is currently being quit, this will not affect the persisted data because
|
||||||
// the persistent container would already have been saved in SceneDelegate.sceneDidEnterBackground(_:)
|
// the persistent container would already have been saved in SceneDelegate.sceneDidEnterBackground(_:)
|
||||||
for segment in timelineSegments {
|
for segment in timelineSegments {
|
||||||
for (id, _) in segment {
|
for (id, _) in segment {
|
||||||
mastodonController.persistentContainer.status(for: id)?.decrementReferenceCount()
|
persistentContainer.status(for: id)?.decrementReferenceCount()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue