perf(guide): Show a stale guide while it refreshes, and revalidate with ETag #33
Loading…
Reference in a new issue
No description provided.
Delete branch "perf/guide-stale-etag"
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?
Merge #32 first. Both PRs change the same spots in
HomeViewModelandGuideViewModel, so this branch has #32 merged in. Until #32 lands, this diff includes #32's commit too; afterwards it shows only this PR's changes.What was wrong
Once the cached guide passed its 3-hour TTL (
EpgCachePolicy.DEFAULT_TTL_MS), the Guide, Home's now-playing and Search all waited for a fullxmltv.phpdownload and parse: 3.4 MB gzipped, 22.5 MB of XML from the pool (our IPTV pool server). That happened even when the guide hadn't changed. The pool sends anETagand answers a matchingIf-None-Matchwith a 304, but the app never sent one.What changed
EpgCache.ktreturns a stale entry straight away when it still covers the requested window and channels, and starts one background refresh under the same per-provider lock, so there is still one download at a time. It blocks only when no entry covers the request. A failed refresh keeps the stale guide, and the next open after a minute tries again.EpgRepository.updatesfires whenever a refresh downloads a guide (any 200); a 304 doesn't fire it.HomeViewModel,GuideViewModelandSearchViewModelthen fetch again, which is served from memory. The Guide asks again for the archive (past) listings of rows that had them. Search keeps its current results if the new fetch returns nothing.If-None-Match; on a 304 the entry is marked fresh in memory and nothing is downloaded or parsed. The disk copy keeps its old time, so each later launch revalidates once, costing one 304, until a changed guide rewrites the disk copy. A download for a window the entry doesn't cover goes without the header, since an unchanged guide still wouldn't cover it.forceRefreshstill waits, and also sends the ETag. Nothing in the UI calls it today.EpgRepository.downloadGuidesoGuideDownloadTest.ktcan drive it with a fake server.Verified
testDebugUnitTest,lintDebugandassembleDebugpass on this branch with #32 merged in (591 tests), and with #34 merged on top as well (600 tests). The combined build ran on the emulator.EpgCacheTest.ktreplaces "a stale entry reloads" with 9 cases: stale served then refreshed, 304 keeps the entry, a changed guide tells the screens, one refresh at a time, failure backoff, forced refresh, an uncovered window skips the ETag, the ETag surviving a restart, and a refresh landing afterclearProviderbeing dropped.GuideDownloadTest.ktadds 5 HTTP cases: the header sent or not, 304, a changed ETag, no ETag, and an error status.