Add settings to clear the cache

This commit is contained in:
Thomas Ricouard 2023-02-04 15:08:54 +01:00
parent 288a0eac9f
commit 8c7efb7df5
17 changed files with 61 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import DesignSystem
import Env
import Models
import SwiftUI
import Timeline
struct AccountSettingsView: View {
@Environment(\.dismiss) private var dismiss
@ -16,6 +17,7 @@ struct AccountSettingsView: View {
@State private var isEditingAccount: Bool = false
@State private var isEditingFilters: Bool = false
@State private var cachedPostsCount: Int = 0
let account: Account
let appAccount: AppAccount
@ -49,6 +51,18 @@ struct AccountSettingsView: View {
}
}
.listRowBackground(theme.primaryBackgroundColor)
Section {
Label("settings.account.cached-posts-\(String(cachedPostsCount))", systemImage: "internaldrive")
Button("settings.account.action.delete-cache", role: .destructive) {
Task {
await TimelineCache.shared.clearCache(for: appAccountsManager.currentClient)
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient)
}
}
}
.listRowBackground(theme.primaryBackgroundColor)
Section {
Button(role: .destructive) {
if let token = appAccount.oauthToken {
@ -82,6 +96,9 @@ struct AccountSettingsView: View {
}
}
}
.task {
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient)
}
.navigationTitle(account.safeDisplayName)
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)

View File

@ -138,6 +138,8 @@
"settings.display.font.scaling-%@" = "Escalat de la lletra: %@";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Exploreu";

View File

@ -136,6 +136,8 @@
"settings.display.font.scaling-%@" = "Schriftskalierung: %@";
"settings.about.built-with" = "Ice Cubes wird mit folgender Open-Source-Software erstellt:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
"enum.expand-media.show" = "Alle zeigen";
"enum.expand-media.hide" = "Alle ausblenden";

View File

@ -140,6 +140,8 @@
"settings.other.autoplay-video" = "Auto Play Videos";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Explore";

View File

@ -139,6 +139,8 @@
"settings.other.autoplay-video" = "Auto Play Videos";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Explore";

View File

@ -136,6 +136,8 @@
"settings.display.font.scaling-%@" = "Escalado de tipografía: %@";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
"enum.expand-media.show" = "Siempre";
"enum.expand-media.hide" = "Nunca";

View File

@ -139,6 +139,8 @@
"settings.display.font.scaling-%@" = "Font scaling: %@";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Explorer";

View File

@ -139,6 +139,8 @@
"settings.other.autoplay-video" = "Auto Play dei video";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Esplora";

View File

@ -139,6 +139,8 @@
"settings.other.autoplay-video" = "動画の自動再生";
"settings.about.built-with" = "Ice Cubesは以下のオープンソースソフトウェアで構築されています:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "エクスプローラー";

View File

@ -139,6 +139,8 @@
"settings.display.font.scaling-%@" = "폰트 크기 조절: %@";
"settings.about.built-with" = "Ice Cubes는 다음 오픈 소스 소프트웨어를 사용하여 개발되었습니다:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "둘러보기";

View File

@ -139,6 +139,8 @@
"settings.other.autoplay-video" = "Spill av videoer automatisk";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Utforsk";

View File

@ -136,6 +136,8 @@
"settings.display.font.scaling-%@" = "Font scaling: %@";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Ontdekken";

View File

@ -139,6 +139,8 @@
"settings.display.font.scaling-%@" = "Skalowanie czcionki: %@";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Odkrywaj";

View File

@ -139,6 +139,8 @@
"settings.display.font.scaling-%@" = "Font scaling: %@";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Explorar";

View File

@ -139,6 +139,8 @@
"settings.display.font.scaling-%@" = "Font scaling: %@";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
// MARK: Tabs
"tab.explore" = "Keşfet";

View File

@ -134,6 +134,8 @@
"settings.other.autoplay-video" = "自动播放视频";
"settings.about.built-with" = "Ice Cubes is built with the following Open Source software:";
"settings.about.title" = "Ice Cubes";
"settings.account.cached-posts-%@" = "Cached posts: %@";
"settings.account.action.delete-cache" = "Clear cache";
"settings.display.font" = "时间线字体";
"settings.display.font.system" = "系统";

View File

@ -3,8 +3,8 @@ import Network
import SwiftUI
import Boutique
actor TimelineCache {
static let shared: TimelineCache = .init()
public actor TimelineCache {
public static let shared: TimelineCache = .init()
private func storageFor(_ client: Client) -> SQLiteStorageEngine {
SQLiteStorageEngine.default(appendingPath: client.id)
@ -15,9 +15,20 @@ actor TimelineCache {
private init() {}
public func cachedPostsCount(for client: Client) async -> Int {
await storageFor(client).allKeys().count
}
public func clearCache(for client: Client) async {
let engine = storageFor(client)
do {
try await engine.removeAllData()
} catch { }
}
func set(statuses: [Status], client: Client) async {
guard !statuses.isEmpty else { return }
let statuses = statuses.prefix(upTo: min(300, statuses.count - 1)).map { $0 }
let statuses = statuses.prefix(upTo: min(400, statuses.count - 1)).map { $0 }
do {
let engine = storageFor(client)
try await engine.removeAllData()