Skip to content

fix(data-access): batch getAllFixesWithSuggestionsByOpportunityId (SITES-45307)#1619

Open
mimchome wants to merge 3 commits into
mainfrom
fix/n-plus-1-suggestions-SITES-45307
Open

fix(data-access): batch getAllFixesWithSuggestionsByOpportunityId (SITES-45307)#1619
mimchome wants to merge 3 commits into
mainfrom
fix/n-plus-1-suggestions-SITES-45307

Conversation

@mimchome
Copy link
Copy Markdown
Collaborator

@mimchome mimchome commented May 22, 2026

SITES-45307

Problem

GET /sites/:siteId/opportunities/:oppId/fixes fetches suggestions per fix in a loop -- 2N+1 queries for N fixes. Follow-up from SITES-45274 which identified the pattern during the fixes controller review.

Changes

  • Add getAllFixesWithSuggestionsByOpportunityId to FixEntityCollection -- queries by opportunityId only, 3 PostgREST calls total instead of 2N+1
  • Extract shared grouping logic into #buildFixesWithSuggestions, reused by both the new method and existing getAllFixesWithSuggestionByCreatedAt
  • Type definitions and JSDoc

Consumer: spacecat-api-service #2474 (draft, waiting on this publish)

Validated

Verified on CI dev -- fixes returned with suggestions embedded, matching existing response contract.

Test plan

  • 4 new unit tests (happy path, empty results, validation, error handling)
  • Existing getAllFixesWithSuggestionByCreatedAt tests pass with shared helper

… (SITES-45307)

Extract shared grouping logic into #buildFixesWithSuggestions and add
getAllFixesWithSuggestionsByOpportunityId that queries the junction table
by opportunityId only (3 PostgREST calls total instead of 2N+1).
@github-actions
Copy link
Copy Markdown

This PR will trigger a patch release when merged.

@mimchome mimchome requested a review from danieljchuser May 22, 2026 14:57
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.

1 participant