perf(espn): remember settled day chunks between window refreshes - #754
Open
ChuckBuilds wants to merge 1 commit into
Open
ChuckBuilds wants to merge 1 commit into
ChuckBuilds wants to merge 1 commit into
Conversation
Since ESPN started rejecting date ranges, every scoreboard's hourly Recent/Upcoming refresh re-asks its 22-day window (14 back, 7 ahead) one day at a time. Measured on hdpi 2026-10-02 (NFL, college football, MLB, college baseball, NHL): the hourly refresh was ~270 of 321 ESPN requests and ~21 of 24.6MB in the hour. Days that ended three or more days ago cannot change, and they were 68% of the window's bytes (6.9 of 10.2MB). _fetch_one_chunk now keeps a settled chunk (last day <= UTC today - 3) in memory for 24h as zlib-compressed JSON, keyed by URL, the other params and the chunk, and answers it from there. Both range paths go through it: fetch_espn_scoreboard and BackgroundDataService._fetch_in_date_chunks. Each hit is parsed afresh, failed and capped chunks are not stored, and the memory is bounded (512 entries / 8MB compressed). Against live ESPN, a second refresh of the five hdpi windows went from 111 requests and 10.18MB to 50 requests and 3.23MB with identical events; the memory held 60 entries in 585KB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 47 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 28 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ESPN still rejects
dates=ranges, so each scoreboard's Recent/Upcoming window (14 days back, 7 ahead) costs 22 day requests. The window is re-fetched in full on every hourly update, including the 12+ days whose games finished long ago.src/common/espn_dates._fetch_one_chunknow remembers a chunk once its last day is at least 3 UTC days old ("settled"), for 24 hours, so the hourly refresh only goes to ESPN for days that can still change.groups=80for FBS) + the chunk._fetch_one_chunk(fetch_espn_scoreboardandBackgroundDataService._fetch_in_date_chunks), so every scoreboard gets it. It sits in front of feat(fetch): one ESPN scoreboard cache key and a max-age response cache (fetch service stage 2) #728's response cache, whose 10-minute ceiling the hourly refresh always misses.Type of change
Test plan
mainwindows that night ran 24.9–27.1 MB/h. No frame-timing change. RSS in this branch's window was 20–60 MB above themainwindow just before it, which is inside the range of all fourmainwindows that night apart from two marks (380/384 vs ≤367 MB). The cache itself is capped at 8 MB, so I read that as noise, but it's one window, so it's worth watching.pytest): 8 new tests (only unsettled days re-asked, same events and order, a hit is a copy, params in the key, 24 h expiry, failures not stored, capped month not stored, memory bound, single-day requests untouched).cache_max_agepass-through.test/conftest.pynow pinsespn_dates._utc_todayto 2000-01-01 for every test, so no fixture date counts as settled unless a test pins "today" itself. Without that, twotest_background_data_service_espn_rangestests asking for September 2026 twice started failing on 2026-10-03, once September became settled.Notes for reviewer
The scoreboards also download each expiring window twice. The managers submit the background fetch and then immediately call
_get_weeks_data()for the same window, and the fetch service doesn't merge the two. That's a plugin-side fix in every sports lineage, not part of this PR. Together with it, a window refresh would drop from ~2×10 MB to ~3 MB.🤖 Generated with Claude Code