mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
fix(cache): move odds key check before live/scoreboard in get_data_type_from_key (#256)
* fix(cache): move odds key check before live/scoreboard check in get_data_type_from_key Cache keys like odds_espn_nba_game_123_live contain 'live', so they were matched by the generic ['live', 'current', 'scoreboard'] branch (sports_live, 30s TTL) before the 'odds' branch was ever reached. This caused live odds to expire every 30 seconds instead of every 120 seconds, hitting the ESPN odds API 4x more often than intended and risking rate-limiting. Fix: move the 'odds' check above the 'live'/'current'/'scoreboard' check so the more-specific prefix wins. No regressions: pure live_*/scoreboard_* keys (without 'odds') still route to sports_live. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(cache): remove dead soccer branch in get_data_type_from_key The inner `if 'soccer' in key_lower: return 'sports_live'` branch was dead code — both the soccer and non-soccer paths returned the same 'sports_live' value. Collapse to a single return statement. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Chuck <chuck@example.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
21
src/cache/cache_strategy.py
vendored
21
src/cache/cache_strategy.py
vendored
@@ -194,10 +194,18 @@ class CacheStrategy:
|
|||||||
"""
|
"""
|
||||||
key_lower = key.lower()
|
key_lower = key.lower()
|
||||||
|
|
||||||
# Live sports data
|
# Odds data — checked FIRST because odds keys may also contain 'live'/'current'
|
||||||
|
# (e.g. odds_espn_nba_game_123_live). The odds TTL (120s for live, 1800s for
|
||||||
|
# upcoming) must win over the generic sports_live TTL (30s) to avoid hitting
|
||||||
|
# the ESPN odds API every 30 seconds per game.
|
||||||
|
if 'odds' in key_lower:
|
||||||
|
# For live games, use shorter cache; for upcoming games, use longer cache
|
||||||
|
if any(x in key_lower for x in ['live', 'current']):
|
||||||
|
return 'odds_live' # Live odds change more frequently (120s TTL)
|
||||||
|
return 'odds' # Regular odds for upcoming games (1800s TTL)
|
||||||
|
|
||||||
|
# Live sports data (only reached if key does NOT contain 'odds')
|
||||||
if any(x in key_lower for x in ['live', 'current', 'scoreboard']):
|
if any(x in key_lower for x in ['live', 'current', 'scoreboard']):
|
||||||
if 'soccer' in key_lower:
|
|
||||||
return 'sports_live' # Soccer live data is very time-sensitive
|
|
||||||
return 'sports_live'
|
return 'sports_live'
|
||||||
|
|
||||||
# Weather data
|
# Weather data
|
||||||
@@ -214,13 +222,6 @@ class CacheStrategy:
|
|||||||
if 'news' in key_lower:
|
if 'news' in key_lower:
|
||||||
return 'news'
|
return 'news'
|
||||||
|
|
||||||
# Odds data - differentiate between live and upcoming games
|
|
||||||
if 'odds' in key_lower:
|
|
||||||
# For live games, use shorter cache; for upcoming games, use longer cache
|
|
||||||
if any(x in key_lower for x in ['live', 'current']):
|
|
||||||
return 'odds_live' # Live odds change more frequently
|
|
||||||
return 'odds' # Regular odds for upcoming games
|
|
||||||
|
|
||||||
# Sports schedules and team info
|
# Sports schedules and team info
|
||||||
if any(x in key_lower for x in ['schedule', 'team_map', 'league']):
|
if any(x in key_lower for x in ['schedule', 'team_map', 'league']):
|
||||||
return 'sports_schedules'
|
return 'sports_schedules'
|
||||||
|
|||||||
Reference in New Issue
Block a user