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
|
private var retryDelay: Int = 10
|
||||||
|
|
||||||
public enum Stream: String {
|
public enum Stream: String {
|
||||||
case publicTimeline = "public"
|
case federated = "public"
|
||||||
|
case local
|
||||||
case user
|
case user
|
||||||
case direct
|
case direct
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ public struct TimelineView: View {
|
||||||
}
|
}
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
viewModel.canFilterTimeline = canFilterTimeline
|
||||||
viewModel.isTimelineVisible = true
|
viewModel.isTimelineVisible = true
|
||||||
|
|
||||||
if viewModel.client == nil {
|
if viewModel.client == nil {
|
||||||
|
|
|
@ -48,12 +48,18 @@ import SwiftUI
|
||||||
// Internal source of truth for a timeline.
|
// Internal source of truth for a timeline.
|
||||||
private(set) var datasource = TimelineDatasource()
|
private(set) var datasource = TimelineDatasource()
|
||||||
private let cache = TimelineCache()
|
private let cache = TimelineCache()
|
||||||
|
private var isCacheEnabled: Bool {
|
||||||
|
canFilterTimeline && timeline.supportNewestPagination
|
||||||
|
}
|
||||||
|
|
||||||
@ObservationIgnored
|
@ObservationIgnored
|
||||||
private var visibileStatuses: [Status] = []
|
private var visibileStatuses: [Status] = []
|
||||||
|
|
||||||
private var canStreamEvents: Bool = true
|
private var canStreamEvents: Bool = true
|
||||||
|
|
||||||
|
@ObservationIgnored
|
||||||
|
var canFilterTimeline: Bool = true
|
||||||
|
|
||||||
var client: Client? {
|
var client: Client? {
|
||||||
didSet {
|
didSet {
|
||||||
if oldValue != client {
|
if oldValue != client {
|
||||||
|
@ -152,20 +158,20 @@ import SwiftUI
|
||||||
|
|
||||||
extension TimelineViewModel {
|
extension TimelineViewModel {
|
||||||
private func cache() async {
|
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)
|
await cache.set(statuses: datasource.get(), client: client.id, filter: timeline.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getCachedStatuses() async -> [Status]? {
|
private func getCachedStatuses() async -> [Status]? {
|
||||||
if let client {
|
if let client, isCacheEnabled {
|
||||||
return await cache.getStatuses(for: client.id, filter: timeline.id)
|
return await cache.getStatuses(for: client.id, filter: timeline.id)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private func clearCache(filter: TimelineFilter) async {
|
private func clearCache(filter: TimelineFilter) async {
|
||||||
if let client {
|
if let client, isCacheEnabled {
|
||||||
await cache.clearCache(for: client.id, filter: filter.id)
|
await cache.clearCache(for: client.id, filter: filter.id)
|
||||||
await cache.setLatestSeenStatuses([], for: client, filter: filter.id)
|
await cache.setLatestSeenStatuses([], for: client, filter: filter.id)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue