perf(channels): Save the channel list to disk and show it before refreshing #32

Merged
namillis merged 1 commit from perf/channel-disk-cache into main 2026-11-09 14:43:45 +00:00
Owner

What was wrong

LiveChannelCache kept each provider's full channel list in memory for 10 minutes only. Every cold start downloaded and parsed get_live_streams again (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.kt writes each Xtream provider's parsed list to cache/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.
  • On launch the disk copy is returned at once and refreshed in the background. A copy older than the 10-minute TTL is also returned at once while one background refresh runs. A failed refresh is retried up to 4 times, 60 s apart; after that, the next screen that asks starts a new one. Only a provider with no list at all makes the caller wait. Empty lists are still never cached.
  • A copy read from disk is never treated as fresh, whatever its age, because it has no pool events (poolEvent, the live game a Live Now channel carries, is never written). HomeViewModel and GuideViewModel follow ProviderRepository.liveChannelUpdates and 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.
  • Home's own 10-minute refresh now calls freshLiveChannels, so it checks its list against a newly downloaded one, not against the cached copy (which would always match).
  • Sports' Live Now list still uses only a fresh in-memory list (cachedLiveChannels), since it needs the events, so on a cold start it fetches that one category from the network as before.
  • ProvidersViewModel deletes a provider's file when it is edited or deleted, next to the guide cache it already clears.
  • M3U lists stay in memory only. Their catch-up templates can hold credentials, and the player loads the playlist anyway.
  • The cache is now injected into ProviderRepository, so LiveNowEventsTest.kt and PoolFeaturesCacheTest.kt pass a memory-only one.

Verified

  • testDebugUnitTest (578 tests, 18 of them in LiveChannelCacheTest, which covers the disk round trip, stale-while-refresh, retries, clearing and file naming), lintDebug and assembleDebug pass.

  • 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:

    Run 1 Run 2 Run 3
    No disk copy (as on main) 1,561 ms 20,631 ms (network stall) 1,497 ms
    Disk copy 482 ms 402 ms 409 ms

    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.

## What was wrong `LiveChannelCache` kept each provider's full channel list in memory for 10 minutes only. Every cold start downloaded and parsed `get_live_streams` again (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.kt` writes each Xtream provider's parsed list to `cache/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. - On launch the disk copy is returned at once and refreshed in the background. A copy older than the 10-minute TTL is also returned at once while one background refresh runs. A failed refresh is retried up to 4 times, 60 s apart; after that, the next screen that asks starts a new one. Only a provider with no list at all makes the caller wait. Empty lists are still never cached. - A copy read from disk is never treated as fresh, whatever its age, because it has no pool events (`poolEvent`, the live game a Live Now channel carries, is never written). `HomeViewModel` and `GuideViewModel` follow `ProviderRepository.liveChannelUpdates` and 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. - Home's own 10-minute refresh now calls `freshLiveChannels`, so it checks its list against a newly downloaded one, not against the cached copy (which would always match). - Sports' Live Now list still uses only a fresh in-memory list (`cachedLiveChannels`), since it needs the events, so on a cold start it fetches that one category from the network as before. - `ProvidersViewModel` deletes a provider's file when it is edited or deleted, next to the guide cache it already clears. - M3U lists stay in memory only. Their catch-up templates can hold credentials, and the player loads the playlist anyway. - The cache is now injected into `ProviderRepository`, so `LiveNowEventsTest.kt` and `PoolFeaturesCacheTest.kt` pass a memory-only one. ## Verified - `testDebugUnitTest` (578 tests, 18 of them in `LiveChannelCacheTest`, which covers the disk round trip, stale-while-refresh, retries, clearing and file naming), `lintDebug` and `assembleDebug` pass. - 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: | | Run 1 | Run 2 | Run 3 | |---|---|---|---| | No disk copy (as on `main`) | 1,561 ms | 20,631 ms (network stall) | 1,497 ms | | Disk copy | 482 ms | 402 ms | 409 ms | 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.
perf(channels): Save the channel list to disk and show it before refreshing
All checks were successful
CI / test (pull_request) Successful in 7m6s
8a5fa8e97a
Every cold start waited for the full get_live_streams list (about 7.8 MB of
JSON for the pool) before Home, the Guide, Search or Sports had it, because
LiveChannelCache only kept it in memory for 10 minutes.

LiveChannelCache now writes each Xtream provider's parsed list to
cache/channel_cache, named by a hash of the provider's id, URL and login.
On launch the disk copy is returned straight away and refreshed once in the
background. A copy older than the 10-minute TTL is also served at once
while one background refresh runs, retried a few times if it fails. Only a
provider with no list at all makes the caller wait.

The disk copy has no pool events, so Home and the Guide now follow
ProviderRepository.liveChannelUpdates and swap in the new list when it
lands. The Guide keeps rows whose channel didn't change, and the focus
stays where it was. Home's own stale refresh uses freshLiveChannels so it
compares against the new list.

M3U lists stay in memory only: their catch-up templates can hold
credentials, and the player loads the playlist anyway. Editing or deleting
a provider deletes its file. Empty lists are still never cached.
namillis deleted branch perf/channel-disk-cache 2026-11-09 14:43:45 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
namillis/LiveWireTV!32
No description provided.