Compare commits

..

2 Commits

8 changed files with 36 additions and 10 deletions

View File

@ -30,6 +30,10 @@ class MastodonController {
}
}
static func resetAll() {
all = [:]
}
private let transient: Bool
private(set) lazy var persistentContainer = MastodonCachePersistentStore(for: accountInfo, transient: transient)

View File

@ -15,7 +15,7 @@ class ConversationTableViewController: EnhancedTableViewController {
static let showPostsImage = UIImage(systemName: "eye.fill")!
static let hidePostsImage = UIImage(systemName: "eye.slash.fill")!
let mastodonController: MastodonController
weak var mastodonController: MastodonController!
let mainStatusID: String
let mainStatusState: StatusState
@ -43,8 +43,9 @@ class ConversationTableViewController: EnhancedTableViewController {
}
deinit {
guard let persistentContainer = mastodonController?.persistentContainer else { return }
for (id, _) in statuses {
mastodonController.persistentContainer.status(for: id)?.decrementReferenceCount()
persistentContainer.status(for: id)?.decrementReferenceCount()
}
}

View File

@ -12,7 +12,7 @@ import Pachyderm
class ExploreViewController: EnhancedTableViewController {
let mastodonController: MastodonController
weak var mastodonController: MastodonController!
var dataSource: DataSource!

View File

@ -17,7 +17,7 @@ class NotificationsTableViewController: EnhancedTableViewController {
private let followRequestCell = "followRequestCell"
private let unknownCell = "unknownCell"
let mastodonController: MastodonController
weak var mastodonController: MastodonController!
let excludedTypes: [Pachyderm.Notification.Kind]
let groupTypes = [Notification.Kind.favourite, .reblog, .follow]

View File

@ -15,6 +15,7 @@ struct AdvancedPrefsView : View {
List {
formattingSection
automationSection
cachingSection
}.listStyle(GroupedListStyle())
.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 {

View File

@ -62,8 +62,7 @@ class ProfileTableViewController: EnhancedTableViewController {
}
deinit {
if let id = accountID {
let container = mastodonController.persistentContainer
if let id = accountID, let container = mastodonController?.persistentContainer {
container.backgroundContext.perform {
container.account(for: id, in: container.backgroundContext)?.decrementReferenceCount()
}

View File

@ -14,7 +14,7 @@ class StatusActionAccountListTableViewController: EnhancedTableViewController {
private let statusCell = "statusCell"
private let accountCell = "accountCell"
let mastodonController: MastodonController
weak var mastodonController: MastodonController!
let actionType: ActionType
let statusID: String
@ -59,8 +59,7 @@ class StatusActionAccountListTableViewController: EnhancedTableViewController {
}
deinit {
if let accountIDs = self.accountIDs {
let container = self.mastodonController.persistentContainer
if let accountIDs = self.accountIDs, let container = mastodonController?.persistentContainer {
container.backgroundContext.perform {
for id in accountIDs {
container.account(for: id, in: container.backgroundContext)?.decrementReferenceCount()

View File

@ -39,12 +39,13 @@ class TimelineTableViewController: EnhancedTableViewController {
}
deinit {
guard let persistentContainer = mastodonController?.persistentContainer else { return }
// decrement reference counts of any statuses we still have
// 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(_:)
for segment in timelineSegments {
for (id, _) in segment {
mastodonController.persistentContainer.status(for: id)?.decrementReferenceCount()
persistentContainer.status(for: id)?.decrementReferenceCount()
}
}
}