feat(guide): Ask the pool for only the guide window the cache keeps #35

Merged
namillis merged 1 commit from feat/guide-window into main 2026-11-09 16:01:01 +00:00
Owner

What was wrong

The pool's xmltv.php (the pool is our IPTV pool server) sends everything it keeps: 6 hours back and 36 ahead, 3.4 MB gzipped and about 85,000 programmes for the tv3 test login. LiveWire parses all of it and then drops everything outside the window it caches (EpgCachePolicy.downloadWindow). The pool now has a guide_window feature that sends only a given window. This is the app side of that contract.

What changed

  • PoolSignals.kt adds GUIDE_WINDOW, gated the same way as retry, stop, sources and event_info.
  • EpgRepository.kt adds past_hours and future_hours to the guide URL when the provider's pool_info lists guide_window and the request has a window. A plain Xtream panel, an M3U guide and a request with no window (onboarding) get the full guide as before.
  • EpgCachePolicy.poolGuideRequest turns the parsed window into whole hours counted from the start of the current hour, rounded outward and clamped to the pool's limits (0-6 back, 1-36 ahead).
  • The cache records the window the pool actually sent (GuideDownload.Loaded.window, used by EpgCache.kt). EpgCachePolicy.poolGuideCovered works it out from the response's Date header, the pool's clock, not the TV's. So a request the pool clamped, a TV clock that is off, or a request that crosses the hour is stored as the smaller window it really is, and covers() keeps rejecting requests it can't serve. A narrower window isn't treated as an error.

Verified

  • testDebugUnitTest (617 tests), lintDebug and assembleDebug pass. New tests: EpgCachePolicyTest.kt has the hour rounding, clamping, pool clocks an hour ahead and behind, and a 5,000-case check that the stored window is never wider than what the pool sent. GuideDownloadTest.kt checks the URL and the Date-based window. EpgGuideWindowTest.kt checks the gate (feature listed, not listed, plain panel, M3U, no window) and that a clamped window makes a request beyond it download again instead of being served short.
  • The live pool, against the contract, with tv3: every window kept all 2,367 channels, had no programme outside it, and answered a repeat with its ETag with a 304. Out-of-range and non-numeric values gave the full guide.
  • LiveWireTV_API34 emulator with tv3, temporary logging (removed before commit), saved guide deleted before each of 4 cold starts. Home asked for past_hours=4&future_hours=21, and the stored window matched the parsed one exactly. Both branches kept the same 73,659 programmes after parsing. Median download plus parse: 4.4 s on main, 4.2 s here. The Guide and Search were then served from that one download, and an aged entry revalidated with a 304 within the hour.

Smaller saving than the contract's table

The contract measured the Guide's window (about 3 back, 14 ahead, 2.4 MB). In practice Home opens first, and its window is 25 hours long (now - 2h .. now + 12h, plus downloadWindow's 2 hours before, and 6 hours and the 3-hour TTL after). That is 4 back and 21 ahead: 3.08 MB against 3.40 MB for the full guide, about 9% less. Shortening Home's window would save more: 4 back and 12 ahead is 2.24 MB. That changes what Home's channel info shows, so it isn't in this PR.

## What was wrong The pool's `xmltv.php` (the pool is our IPTV pool server) sends everything it keeps: 6 hours back and 36 ahead, 3.4 MB gzipped and about 85,000 programmes for the tv3 test login. LiveWire parses all of it and then drops everything outside the window it caches (`EpgCachePolicy.downloadWindow`). The pool now has a `guide_window` feature that sends only a given window. This is the app side of that contract. ## What changed - `PoolSignals.kt` adds `GUIDE_WINDOW`, gated the same way as `retry`, `stop`, `sources` and `event_info`. - `EpgRepository.kt` adds `past_hours` and `future_hours` to the guide URL when the provider's `pool_info` lists `guide_window` and the request has a window. A plain Xtream panel, an M3U guide and a request with no window (onboarding) get the full guide as before. - `EpgCachePolicy.poolGuideRequest` turns the parsed window into whole hours counted from the start of the current hour, rounded outward and clamped to the pool's limits (0-6 back, 1-36 ahead). - The cache records the window the pool actually sent (`GuideDownload.Loaded.window`, used by `EpgCache.kt`). `EpgCachePolicy.poolGuideCovered` works it out from the response's `Date` header, the pool's clock, not the TV's. So a request the pool clamped, a TV clock that is off, or a request that crosses the hour is stored as the smaller window it really is, and `covers()` keeps rejecting requests it can't serve. A narrower window isn't treated as an error. ## Verified - `testDebugUnitTest` (617 tests), `lintDebug` and `assembleDebug` pass. New tests: `EpgCachePolicyTest.kt` has the hour rounding, clamping, pool clocks an hour ahead and behind, and a 5,000-case check that the stored window is never wider than what the pool sent. `GuideDownloadTest.kt` checks the URL and the `Date`-based window. `EpgGuideWindowTest.kt` checks the gate (feature listed, not listed, plain panel, M3U, no window) and that a clamped window makes a request beyond it download again instead of being served short. - The live pool, against the contract, with tv3: every window kept all 2,367 channels, had no programme outside it, and answered a repeat with its ETag with a 304. Out-of-range and non-numeric values gave the full guide. - LiveWireTV_API34 emulator with tv3, temporary logging (removed before commit), saved guide deleted before each of 4 cold starts. Home asked for `past_hours=4&future_hours=21`, and the stored window matched the parsed one exactly. Both branches kept the same 73,659 programmes after parsing. Median download plus parse: 4.4 s on `main`, 4.2 s here. The Guide and Search were then served from that one download, and an aged entry revalidated with a 304 within the hour. ## Smaller saving than the contract's table The contract measured the Guide's window (about 3 back, 14 ahead, 2.4 MB). In practice Home opens first, and its window is 25 hours long (`now - 2h .. now + 12h`, plus `downloadWindow`'s 2 hours before, and 6 hours and the 3-hour TTL after). That is 4 back and 21 ahead: 3.08 MB against 3.40 MB for the full guide, about 9% less. Shortening Home's window would save more: 4 back and 12 ahead is 2.24 MB. That changes what Home's channel info shows, so it isn't in this PR.
feat(guide): Ask the pool for only the guide window the cache keeps
All checks were successful
CI / test (pull_request) Successful in 6m0s
62e4938bba
The pool's xmltv.php sends 6 hours back and 36 ahead, and LiveWire then
drops everything outside the window it caches. A pool that lists
guide_window in pool_info now takes past_hours and future_hours and
sends only that window.

EpgRepository asks for those hours when the provider lists the
feature (PoolSignals.GUIDE_WINDOW), for a request that has a window.
EpgCachePolicy.poolGuideRequest turns the parsed window into whole
hours from the start of the current hour, rounded outward and clamped
to 0-6 back and 1-36 ahead. A plain panel, an M3U guide and a request
without a window get the full guide as before.

The cache records the window the pool actually sent. poolGuideCovered
works it out from the pool's Date header rather than the TV's clock,
so a clamped request, a TV clock that is off, or a request that
crosses the hour is stored as the smaller window it is, and covers()
keeps rejecting requests it can't serve.
namillis deleted branch feat/guide-window 2026-11-09 16:01:01 +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!35
No description provided.