Don't cache non filterable timeline

This commit is contained in:
Thomas Ricouard 2024-01-03 14:59:28 +01:00
parent ad4995ad70
commit 2eb15b48d4
3 changed files with 12 additions and 4 deletions

View file

@ -17,7 +17,8 @@ import Observation
private var retryDelay: Int = 10
public enum Stream: String {
case publicTimeline = "public"
case federated = "public"
case local
case user
case direct
}

View file

@ -114,6 +114,7 @@ public struct TimelineView: View {
}
.navigationBarTitleDisplayMode(.inline)
.onAppear {
viewModel.canFilterTimeline = canFilterTimeline
viewModel.isTimelineVisible = true
if viewModel.client == nil {

View file

@ -48,12 +48,18 @@ import SwiftUI
// Internal source of truth for a timeline.
private(set) var datasource = TimelineDatasource()
private let cache = TimelineCache()
private var isCacheEnabled: Bool {
canFilterTimeline && timeline.supportNewestPagination
}
@ObservationIgnored
private var visibileStatuses: [Status] = []
private var canStreamEvents: Bool = true
@ObservationIgnored
var canFilterTimeline: Bool = true
var client: Client? {
didSet {
if oldValue != client {
@ -152,20 +158,20 @@ import SwiftUI
extension TimelineViewModel {
private func cache() async {
if let client, timeline.supportNewestPagination {
if let client, isCacheEnabled {
await cache.set(statuses: datasource.get(), client: client.id, filter: timeline.id)
}
}
private func getCachedStatuses() async -> [Status]? {
if let client {
if let client, isCacheEnabled {
return await cache.getStatuses(for: client.id, filter: timeline.id)
}
return nil
}
private func clearCache(filter: TimelineFilter) async {
if let client {
if let client, isCacheEnabled {
await cache.clearCache(for: client.id, filter: filter.id)
await cache.setLatestSeenStatuses([], for: client, filter: filter.id)
}