perf(channels): Save the channel list to disk and show it before refreshing #32
Loading…
Reference in a new issue
No description provided.
Delete branch "perf/channel-disk-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What was wrong
LiveChannelCachekept each provider's full channel list in memory for 10 minutes only. Every cold start downloaded and parsedget_live_streamsagain (23,553 channels, about 7.8 MB of JSON from the pool, our IPTV pool server) before Home's All channels, Favorites and Recently watched, the Guide, Search or the player had a list. After the 10 minutes ran out, the next screen to ask waited for the whole download again.What changed
LiveChannelCache.ktwrites each Xtream provider's parsed list tocache/channel_cache(about 3.2 MB for the pool). The file name is a hash of the provider's id, URL and login, never the URL or login itself. Saving a list deletes any file the same provider left under an earlier login or URL.poolEvent, the live game a Live Now channel carries, is never written).HomeViewModelandGuideViewModelfollowProviderRepository.liveChannelUpdatesand swap in the new list when it lands. Home then rebuilds All channels, Favorites and Recently watched and reloads now-playing once (from the guide cache). The Guide keeps the rows whose channel didn't change, so focus and fetched archive listings stay put.freshLiveChannels, so it checks its list against a newly downloaded one, not against the cached copy (which would always match).cachedLiveChannels), since it needs the events, so on a cold start it fetches that one category from the network as before.ProvidersViewModeldeletes a provider's file when it is edited or deleted, next to the guide cache it already clears.ProviderRepository, soLiveNowEventsTest.ktandPoolFeaturesCacheTest.ktpass a memory-only one.Verified
testDebugUnitTest(578 tests, 18 of them inLiveChannelCacheTest, which covers the disk round trip, stale-while-refresh, retries, clearing and file naming),lintDebugandassembleDebugpass.LiveWireTV_API34 emulator signed in with the tv3 test login, with temporary timing logs (removed before commit). Time from Home starting its load until it had the full list:
main)With the disk copy, the refreshed list (with its 29-30 pool events) reached Home 0.6 to 1.1 s after the rails showed. The emulator runs on a fast Mac, so the saving on a TV, where parsing is slower, should be larger. I haven't measured on a TV.
Emulator throttled to EDGE: the Guide opened from the disk copy, with the Live Now rows showing the real channels' programmes. After restoring the network the retried refresh landed, and the same rows switched to their single game blocks with focus still on row 1.
Editing the Pool provider deleted its file. The next launch downloaded and saved the list again. The saved file holds no login, password or server address.
Not changed: the category rails still load from the network on every launch, so Home's first paint still waits about 1 s for them.