jashdoshi77 commited on
Commit
feffca7
·
1 Parent(s): 5ad7521

Fix: Synchronous cache warming for accurate starters and PPG data

Browse files
Files changed (1) hide show
  1. server.py +8 -6
server.py CHANGED
@@ -376,15 +376,17 @@ logger.info("Background scheduler started with jobs: update_elo (1h), sync_predi
376
  # =============================================================================
377
  def startup_cache_warming():
378
  """Warm all caches on startup for instant first requests."""
379
- logger.info("Starting cache warming on startup...")
380
  try:
381
- # Warm starter cache in background (takes ~5 seconds)
382
- threading.Thread(target=warm_starter_cache, daemon=True).start()
383
- logger.info("Starter cache warming initiated")
 
384
  except Exception as e:
385
- logger.warning(f"Startup cache warming error (non-critical): {e}")
 
386
 
387
- # Run startup warming
388
  startup_cache_warming()
389
 
390
  # =============================================================================
 
376
  # =============================================================================
377
  def startup_cache_warming():
378
  """Warm all caches on startup for instant first requests."""
379
+ logger.info("Starting SYNCHRONOUS cache warming on startup...")
380
  try:
381
+ # Warm starter cache SYNCHRONOUSLY so data is ready before first request
382
+ # This ensures accurate, real NBA API data is shown immediately
383
+ warm_starter_cache()
384
+ logger.info("Starter cache warming COMPLETE - real data ready!")
385
  except Exception as e:
386
+ logger.warning(f"Startup cache warming error: {e}")
387
+ logger.warning("Will use fallback data until next refresh")
388
 
389
+ # Run startup warming (blocks until complete for accurate data)
390
  startup_cache_warming()
391
 
392
  # =============================================================================