Stop unnecessary Spotify API call every 60s from enrichment status polling

This commit is contained in:
Broque Thomas 2026-03-12 12:06:25 -07:00
parent 8d059b2e65
commit 66e9457d0e
2 changed files with 7 additions and 8 deletions

View file

@ -336,7 +336,7 @@ class SpotifyClient:
self._auth_cache_lock = threading.Lock()
self._auth_cached_result: Optional[bool] = None
self._auth_cache_time: float = 0
self._AUTH_CACHE_TTL = 60 # seconds
self._AUTH_CACHE_TTL = 300 # 5 minutes — auth status rarely changes, no need to probe often
self._setup_client()
def _is_spotify_id(self, id_str: str) -> bool:

View file

@ -97,15 +97,14 @@ class SpotifyWorker:
is_idle = is_actually_running and not self.paused and self.stats['pending'] == 0 and self.current_item is None
try:
# During rate limit or post-ban cooldown, report as authenticated
# but don't call is_spotify_authenticated() — that would trigger an
# auth probe which resets the rate limit timer.
# NEVER call is_spotify_authenticated() here — get_stats() is called
# every 2 seconds by the WebSocket status loop. The auth probe has a
# 60-second cache, so it would fire a real Spotify API call (current_user)
# every 60 seconds indefinitely, wasting API quota and risking rate limits.
# Instead, use sp presence as a lightweight proxy for "configured".
rate_limited = self.client.is_rate_limited()
in_cooldown = self.client.get_post_ban_cooldown_remaining() > 0
if rate_limited or in_cooldown:
authenticated = True # We're authenticated, just banned/cooling down
else:
authenticated = self.client.is_spotify_authenticated()
authenticated = self.client.sp is not None
except Exception:
authenticated = False
rate_limited = False