Limit number of stored feed items

This commit is contained in:
Arkadiusz Fal 2022-12-11 16:15:06 +01:00
parent f6a261662c
commit 3c546f96df

View File

@ -5,6 +5,7 @@ import SwiftyJSON
struct FeedCacheModel {
static let shared = FeedCacheModel()
static let limit = 30
let logger = Logger(label: "stream.yattee.cache.feed")
static let diskConfig = DiskConfig(name: "feed")
@ -20,7 +21,7 @@ struct FeedCacheModel {
let date = iso8601DateFormatter.string(from: Date())
logger.info("caching feed \(account.feedCacheKey) -- \(date)")
let feedTimeObject: JSON = ["date": date]
let videosObject: JSON = ["videos": videos.map(\.json).map(\.object)]
let videosObject: JSON = ["videos": videos.prefix(Self.limit).map { $0.json.object }]
try? storage.setObject(feedTimeObject, forKey: feedTimeCacheKey(account.feedCacheKey))
try? storage.setObject(videosObject, forKey: account.feedCacheKey)
}