mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 02:01:02 +00:00
Don't cache non filterable timeline
This commit is contained in:
parent
ad4995ad70
commit
2eb15b48d4
3 changed files with 12 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -114,6 +114,7 @@ public struct TimelineView: View {
|
|||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.onAppear {
|
||||
viewModel.canFilterTimeline = canFilterTimeline
|
||||
viewModel.isTimelineVisible = true
|
||||
|
||||
if viewModel.client == nil {
|
||||
|
|
|
@ -48,11 +48,17 @@ 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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue