Skip to content

Commit d701a15

Browse files
Dimillianjesusjimsa
authored andcommitted
Expand timeline cache retention (Dimillian#2354)
1 parent 9916eb3 commit d701a15

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Packages/Timeline/Sources/Timeline/actors/TimelineCache.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public actor TimelineCache {
102102
// MARK: - Encoding helpers
103103

104104
private extension TimelineCache {
105-
var maxCachedStatuses: Int { 600 }
105+
var maxCachedStatuses: Int { 800 }
106106

107107
private func prepareItemsForCaching(_ items: [TimelineItem]) -> [CachedTimelineItem] {
108108
limitedItems(items, limit: maxCachedStatuses).map { item in
@@ -138,20 +138,21 @@ private extension TimelineCache {
138138
}
139139

140140
private func limitedItems(_ items: [TimelineItem], limit: Int) -> [TimelineItem] {
141+
guard limit > 0 else { return [] }
142+
141143
var collected: [TimelineItem] = []
142144
var statusCount = 0
143145

144146
for item in items {
145-
if statusCount >= limit { break }
146-
147147
switch item {
148148
case .status:
149+
guard statusCount < limit else { continue }
149150
collected.append(item)
150151
statusCount += 1
151152
case .gap:
152-
if statusCount > 0 {
153-
collected.append(item)
154-
}
153+
guard statusCount > 0 else { continue }
154+
collected.append(item)
155+
if statusCount >= limit { return collected }
155156
}
156157
}
157158

0 commit comments

Comments
 (0)