Skip to content

Coalesce in-flight fantasy analysis and harden refresh cache bypass - #284

Merged
sfreeman422 merged 2 commits into
feature/caching-fantasyfrom
copilot/fix-code-for-comments
Sep 9, 2026
Merged

Coalesce in-flight fantasy analysis and harden refresh cache bypass#284
sfreeman422 merged 2 commits into
feature/caching-fantasyfrom
copilot/fix-code-for-comments

Conversation

Copilot AI commented Sep 9, 2026

Copy link
Copy Markdown

Refresh requests in the fantasy overview path could still duplicate concurrent AI generations and might not bypass HTTP/browser caches despite refresh=true. This PR closes both gaps in backend cache behavior and frontend refresh fetch semantics.

  • Backend: analysis cache concurrency + stale-entry handling

    • Added an in-flight promise cache keyed with the same analysis key used by analysisCache.
    • getTradeAnalysis(...) now:
      • returns fresh cached data when valid,
      • deletes expired cache entries on access,
      • reuses existing in-flight generation for identical concurrent requests.
  • Frontend: guaranteed network refresh

    • Refresh calls in useFantasy now pass cache: 'no-store' with the existing ?refresh=true URL to prevent intermediary/browser cache reuse.
  • Coverage updates for new behavior

    • Added focused spec coverage for:
      • concurrent coalescing to a single generate() invocation,
      • stale analysis eviction/regeneration,
      • refresh fetch options including cache: 'no-store'.
const inFlight = this.analysisRequests.get(key);
if (inFlight) return inFlight;

const request = generate()
  .then((analysis) => {
    this.analysisCache.set(key, { expiresAt: Date.now() + AI_ANALYSIS_CACHE_MS, analysis });
    return analysis;
  })
  .finally(() => this.analysisRequests.delete(key));

Copilot AI changed the title [WIP] Fix code based on review comments Coalesce in-flight fantasy analysis and harden refresh cache bypass Sep 9, 2026
Copilot AI requested a review from sfreeman422 September 9, 2026 17:51
@sfreeman422
sfreeman422 marked this pull request as ready for review September 9, 2026 17:51
Copilot AI lite review requested due to automatic review settings September 9, 2026 17:51
@sfreeman422
sfreeman422 merged commit 01e0064 into feature/caching-fantasy Sep 9, 2026
11 checks passed

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 changes are localized, align with the PR’s stated goals, and include targeted test coverage for the new cache/concurrency behaviors.

Pull request overview

This PR tightens “refresh” behavior for the fantasy overview by (1) preventing duplicate concurrent AI trade-analysis generations on the backend via in-flight request coalescing and (2) ensuring frontend refresh requests bypass intermediary/browser caches by explicitly using cache: 'no-store'.

Changes:

  • Backend: added an in-flight promise map to reuse an ongoing generateTradeAnalysis(...) for identical concurrent requests, while also deleting expired cached entries on access.
  • Frontend: refresh requests now pass RequestInit.cache = 'no-store' alongside the existing ?refresh=true query param.
  • Tests: added/updated focused specs to validate refresh fetch options, stale cache eviction/regeneration, and concurrent-request coalescing.
File summaries
File Description
packages/frontend/src/pages/FantasyPage.spec.tsx Asserts refresh fetch calls include { cache: 'no-store' }.
packages/frontend/src/hooks/useFantasy.ts Passes { cache: 'no-store' } for refresh overview requests to force a network fetch.
packages/backend/src/fantasy/fantasy.service.ts Coalesces concurrent analysis generation via analysisRequests and clears expired cache entries.
packages/backend/src/fantasy/fantasy.service.spec.ts Adds test coverage for concurrent coalescing and expired-entry regeneration behavior.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

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