Skip to content

Add incremental TBA match cache with per-event If-Modified-Since support#35

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/implement-local-cache-for-matches
Draft

Add incremental TBA match cache with per-event If-Modified-Since support#35
Copilot wants to merge 2 commits intomasterfrom
copilot/implement-local-cache-for-matches

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

Every call to fetch_all_matches was doing a full re-fetch of all events and all matches, ignoring HTTP conditional-request semantics at the per-event level. Three root causes:

  • A single if_modified_since timestamp (from the events-list response) was reused for every individual event match/team fetch — too coarse-grained.
  • The result dict was replaced wholesale on each fetch, silently discarding previously cached matches and event_teams (noted in a TODO).
  • A single try/except wrapped the entire event loop, so any ApiException(304) from one event aborted all remaining fetches.

Changes (current/backend/TBA.py)

  • Per-event Last-Modified tracking — new event_last_modified dict in the cache stores the Last-Modified response header keyed by event.key after each successful fetch.
  • Per-event conditional requests — each get_event_matches / get_event_teams call uses its own stored timestamp; TBA can return 304 for unchanged events independently.
  • Per-event error isolation — each event fetch is wrapped in its own try/except; a 304 for one event keeps cached data and continues the loop.
  • Fix cache merge — replaced the wholesale dict replacement with result.setdefault(...) so existing matches, event_teams, and event_last_modified are always preserved across fetches.
  • Events-list 304 — handled gracefully by falling back to the cached events list rather than propagating an exception.
  • reset=True — passes empty if_modified_since for every call to force a full re-fetch when needed.
# Before: same stale timestamp for every event
matches = api_instance.get_event_matches(e.key, if_modified_since=if_modified_since)

# After: per-event timestamp; 304 keeps cached data, loop continues
try:
    matches = api_instance.get_event_matches(event.key, if_modified_since=event_if_modified)
    result['matches'][event.key] = matches
    result['event_last_modified'][event.key] = api_instance.api_client.last_response.getheader('Last-Modified', '')
except ApiException as exc:
    if exc.status == 304:
        pass  # cached data retained

Structure

New current/ folder mirrors 2024/backend/ and serves as the active season backend. swagger_client is symlinked from 2024/backend/swagger_client to avoid duplication.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: simra <2946735+simra@users.noreply.github.com>
Copilot AI changed the title [WIP] Add local cache for match data to reduce re-fetching Add incremental TBA match cache with per-event If-Modified-Since support Feb 25, 2026
Copilot AI requested a review from simra February 25, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants