Remove Sendable conformance on Client as it's not needed

This commit is contained in:
Thomas Ricouard 2023-02-19 07:51:16 +01:00
parent 03d60d2236
commit 65e63c4586
5 changed files with 15 additions and 15 deletions

View file

@ -57,8 +57,8 @@ struct AccountSettingsView: View {
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)
await TimelineCache.shared.clearCache(for: appAccountsManager.currentClient.id)
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient.id)
}
}
}
@ -69,7 +69,7 @@ struct AccountSettingsView: View {
if let token = appAccount.oauthToken {
Task {
let client = Client(server: appAccount.server, oauthToken: token)
await TimelineCache.shared.clearCache(for: client)
await TimelineCache.shared.clearCache(for: client.id)
if let sub = pushNotifications.subscriptions.first(where: { $0.account.token == token }) {
await sub.deleteSubscription()
}
@ -100,7 +100,7 @@ struct AccountSettingsView: View {
}
}
.task {
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient)
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient.id)
}
.navigationTitle(account.safeDisplayName)
.scrollContentBackground(.hidden)

View file

@ -106,7 +106,7 @@ struct SettingsTabs: View {
let sub = pushNotifications.subscriptions.first(where: { $0.account.token == token })
{
let client = Client(server: account.server, oauthToken: token)
await TimelineCache.shared.clearCache(for: client)
await TimelineCache.shared.clearCache(for: client.id)
await sub.deleteSubscription()
appAccountsManager.delete(account: account)
}

View file

@ -2,7 +2,7 @@ import Foundation
import Models
import SwiftUI
public final class Client: ObservableObject, Equatable, Identifiable, Hashable, @unchecked Sendable {
public final class Client: ObservableObject, Equatable, Identifiable, Hashable {
public static func == (lhs: Client, rhs: Client) -> Bool {
lhs.isAuth == rhs.isAuth &&
lhs.server == rhs.server &&

View file

@ -6,8 +6,8 @@ import SwiftUI
public actor TimelineCache {
public static let shared: TimelineCache = .init()
private func storageFor(_ client: Client) -> SQLiteStorageEngine {
SQLiteStorageEngine.default(appendingPath: client.id)
private func storageFor(_ client: String) -> SQLiteStorageEngine {
SQLiteStorageEngine.default(appendingPath: client)
}
private let decoder = JSONDecoder()
@ -15,18 +15,18 @@ public actor TimelineCache {
private init() {}
public func cachedPostsCount(for client: Client) async -> Int {
public func cachedPostsCount(for client: String) async -> Int {
await storageFor(client).allKeys().count
}
public func clearCache(for client: Client) async {
public func clearCache(for client: String) async {
let engine = storageFor(client)
do {
try await engine.removeAllData()
} catch {}
}
func set(statuses: [Status], client: Client) async {
func set(statuses: [Status], client: String) async {
guard !statuses.isEmpty else { return }
let statuses = statuses.prefix(upTo: min(600, statuses.count - 1)).map { $0 }
do {
@ -39,7 +39,7 @@ public actor TimelineCache {
} catch {}
}
func getStatuses(for client: Client) async -> [Status]? {
func getStatuses(for client: String) async -> [Status]? {
let engine = storageFor(client)
do {
return try await engine

View file

@ -13,7 +13,7 @@ class TimelineViewModel: ObservableObject {
timelineTask?.cancel()
timelineTask = Task {
if timeline == .latest, let client {
await cache.clearCache(for: client)
await cache.clearCache(for: client.id)
timeline = .home
}
if oldValue != timeline {
@ -137,13 +137,13 @@ class TimelineViewModel: ObservableObject {
extension TimelineViewModel {
private func cacheHome() async {
if let client, timeline == .home {
await cache.set(statuses: datasource.get(), client: client)
await cache.set(statuses: datasource.get(), client: client.id)
}
}
private func getCachedStatuses() async -> [Status]? {
if let client {
return await cache.getStatuses(for: client)
return await cache.getStatuses(for: client.id)
}
return nil
}