Skip to content

fix(fantasy): stop marketValue from returning null on cold cache - #291

Merged
sfreeman422 merged 2 commits into
masterfrom
fix/fantasycalc-overview-null-market-values
Sep 11, 2026
Merged

sfreeman422 merged 2 commits into
masterfrom
fix/fantasycalc-overview-null-market-values

Conversation

@sfreeman422

Copy link
Copy Markdown
Collaborator

Problem

marketValue and positionRank were coming back null for all players on the fantasy overview, especially right after a deploy.

Root cause

getFantasyCalcValuesForOverview only waited FANTASYCALC_OVERVIEW_WAIT_MS (150ms) before falling back to an empty values map, but the underlying FantasyCalc request is bounded by FANTASYCALC_TIMEOUT_MS (2000ms). On a cold in-memory cache (e.g. right after a restart/deploy), the overview almost always timed out at 150ms before the fetch could complete, so every player's marketValue/positionRank came back null until a subsequent request warmed the cache.

Verified live: a cold-cache call to getFantasyCalcValuesForOverview returned 0 populated values before the fix, and 423 after.

Fix

Align FANTASYCALC_OVERVIEW_WAIT_MS with FANTASYCALC_TIMEOUT_MS so the first request has a real chance to populate market values before falling back.

Testing

  • npx vitest run src/fantasy/fantasy.service.spec.ts — 25/25 passing
  • Full backend + frontend suite via pre-push hook — 848/848 passing
  • Manual live verification of cold-cache FantasyCalc fetch timing

getFantasyCalcValuesForOverview waited only 150ms before falling back
to an empty values map, but the underlying FantasyCalc request can
take up to FANTASYCALC_TIMEOUT_MS (2000ms). On a cold in-memory cache
(e.g. right after a deploy), the overview almost always timed out
before the fetch completed, so every player's marketValue and
positionRank came back null until a second request warmed the cache.

Align the overview wait with the request timeout so the first
request has a real chance to populate market values.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 11, 2026 20:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Add a delayed-response cold-cache test to prevent regression to the shorter wait.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Aligns the FantasyCalc overview wait with the request timeout so cold-cache requests can populate player values.

Changes:

  • Increases the overview wait from 150 ms to 2 seconds.
  • Documents the cold-cache rationale.
File summaries
File Summary
packages/backend/src/fantasy/fantasy.service.ts Aligns FantasyCalc overview wait timing with the request timeout.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

// Must be long enough for the FantasyCalc request (bounded by FANTASYCALC_TIMEOUT_MS) to actually
// finish on a cold cache; a short wait here mostly guarantees the fallback (all-null marketValues)
// on every first request after a deploy, since the in-memory cache resets on restart.
const FANTASYCALC_OVERVIEW_WAIT_MS = FANTASYCALC_TIMEOUT_MS;

Copilot AI commented Sep 11, 2026

Copy link
Copy Markdown

🟡 Changes recommended

Add a delayed-response cold-cache test to prevent regression to the shorter wait....

Addressed in 62a9879 by adding a delayed cold-cache regression test for getFantasyCalcValuesForOverview that resolves after 300ms and verifies populated values are returned before timeout fallback.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The fix is covered by regression tests and no unresolved review issues remain.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@sfreeman422
sfreeman422 merged commit 876df9f into master Sep 11, 2026
11 checks passed
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.

3 participants