perf(providers): Save the pool's feature list and use it at launch #38

Merged
namillis merged 1 commit from perf/pool-features-disk into main 2026-11-10 02:43:10 +00:00
Owner

What was wrong

Every launch had to get a pool_info answer within 3 seconds (POOL_CHECK_TIMEOUT_MS) before the app used the pool's features: retry, stop, sources, live game info (event_info) and the shorter guide (guide_window). When the pool was slow, during a rebuild pause or the first minute after a deploy, the app treated it as a plain panel for a minute and downloaded the full guide. The pool agent asked for this in its note; the two refinements below are mine.

What changed

  • ProviderFileStore.kt is a new store for small per-provider files. Names are hashes of the provider id and of its URL and login, the same scheme as the channel list cache, so a name never reveals either. Saving replaces the provider's file from an earlier URL or login.
  • ProviderRepository.kt saves each real pool_info answer there. A launch uses the saved list at once and asks pool_info again in the background; the answer replaces the saved list. A real answer is the pool's feature list, or empty for a plain panel (a 404, or an accepted login with no pool shape).
  • A timeout, a 429, a 5xx, a network error or a refused login is not an answer. It keeps the saved list, and the check runs again after a minute (or a 429's Retry-After). With nothing saved, the first call still waits for the answer, as before.
  • Refinement 1, in XtreamClient.kt: a refused login (HTTP 401 or 403, or a 200 with user_info.auth 0) is now PoolCheck.refused. Before, it counted as "plain panel" for the whole run, so a rotated password would have turned the features off and saved an empty list.
  • Refinement 2: only one pool_info check runs at a time per provider, so a launch no longer sends two.
  • forgetProvider (called on edit and delete) also deletes the saved list. The tests that build a ProviderRepository (LiveNowEventsTest.kt, PoolFeaturesCacheTest.kt, EpgGuideWindowTest.kt) pass a memory-only store.

Verified

  • testDebugUnitTest (639 tests), lintDebug and assembleDebug pass. PoolFeaturesSavedTest.kt has 10 cases: the saved list returned while the pool hasn't answered, a new answer replacing it, each failure keeping it and the minute's wait, plain-panel answers saving an empty list, a refused login with nothing saved, six callers at once sending one check, delete, a check ending after delete, file name and contents, and a new login replacing the old file.
  • LiveWireTV_API34 emulator with the tv3 login, temporary logging (removed):
    • First launch with nothing saved waited for pool_info as before and saved a 54-byte file holding only the five feature names. The next launches read it and checked in the background, with one pool_info each.
    • Every pool_info forced to time out (a 1 ms limit in a throwaway build of each, saved guide deleted first): main treated the pool as plain and asked for the full guide. This branch used the saved list and asked for past_hours=2&future_hours=15. The saved file was left unchanged.
  • I didn't test a refused login against the real pool: bad logins count toward the pool's lockout of the IP address, which the real TVs share.
## What was wrong Every launch had to get a `pool_info` answer within 3 seconds (`POOL_CHECK_TIMEOUT_MS`) before the app used the pool's features: retry, stop, sources, live game info (`event_info`) and the shorter guide (`guide_window`). When the pool was slow, during a rebuild pause or the first minute after a deploy, the app treated it as a plain panel for a minute and downloaded the full guide. The pool agent asked for this in its note; the two refinements below are mine. ## What changed - `ProviderFileStore.kt` is a new store for small per-provider files. Names are hashes of the provider id and of its URL and login, the same scheme as the channel list cache, so a name never reveals either. Saving replaces the provider's file from an earlier URL or login. - `ProviderRepository.kt` saves each real `pool_info` answer there. A launch uses the saved list at once and asks `pool_info` again in the background; the answer replaces the saved list. A real answer is the pool's feature list, or empty for a plain panel (a 404, or an accepted login with no pool shape). - A timeout, a 429, a 5xx, a network error or a refused login is not an answer. It keeps the saved list, and the check runs again after a minute (or a 429's `Retry-After`). With nothing saved, the first call still waits for the answer, as before. - Refinement 1, in `XtreamClient.kt`: a refused login (HTTP 401 or 403, or a 200 with `user_info.auth` 0) is now `PoolCheck.refused`. Before, it counted as "plain panel" for the whole run, so a rotated password would have turned the features off and saved an empty list. - Refinement 2: only one `pool_info` check runs at a time per provider, so a launch no longer sends two. - `forgetProvider` (called on edit and delete) also deletes the saved list. The tests that build a `ProviderRepository` (`LiveNowEventsTest.kt`, `PoolFeaturesCacheTest.kt`, `EpgGuideWindowTest.kt`) pass a memory-only store. ## Verified - `testDebugUnitTest` (639 tests), `lintDebug` and `assembleDebug` pass. `PoolFeaturesSavedTest.kt` has 10 cases: the saved list returned while the pool hasn't answered, a new answer replacing it, each failure keeping it and the minute's wait, plain-panel answers saving an empty list, a refused login with nothing saved, six callers at once sending one check, delete, a check ending after delete, file name and contents, and a new login replacing the old file. - LiveWireTV_API34 emulator with the tv3 login, temporary logging (removed): - First launch with nothing saved waited for `pool_info` as before and saved a 54-byte file holding only the five feature names. The next launches read it and checked in the background, with one `pool_info` each. - Every `pool_info` forced to time out (a 1 ms limit in a throwaway build of each, saved guide deleted first): `main` treated the pool as plain and asked for the full guide. This branch used the saved list and asked for `past_hours=2&future_hours=15`. The saved file was left unchanged. - I didn't test a refused login against the real pool: bad logins count toward the pool's lockout of the IP address, which the real TVs share.
perf(providers): Save the pool's feature list and use it at launch
All checks were successful
CI / test (pull_request) Successful in 7m12s
b99cfcb746
Every launch had to get a pool_info answer within 3 seconds before the
app used retry, stop, sources, event_info or guide_window. When the
pool was slow (a rebuild pause, or the first minute after a deploy), the
app treated it as a plain panel for a minute and downloaded the full
guide.

Each real pool_info answer is now saved per provider in a new
ProviderFileStore, named by hashes of the provider id and its URL and
login, like the channel list cache. A launch uses the saved list at
once and asks pool_info again in the background; the answer replaces
it. A real answer is the pool's feature list, or empty for a plain
panel (a 404, an accepted login with no pool shape).

A timeout, a 429, a 5xx, a network error or a refused login is not an
answer: it keeps the saved list and the check is tried again after a
minute (a 429's Retry-After). A refused login used to be cached as
"plain panel" for the run; with nothing saved it now counts as plain
for a minute, like a timeout. With nothing saved, the first call still
waits for the answer, as before.

Only one pool_info check runs at a time per provider, so a launch no
longer sends two. Editing or deleting a provider deletes its saved list.
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!38
No description provided.