Skip to content

Fix N+1 query in opportunities board#150

Closed
NeloNew wants to merge 1 commit intorelaticle:mainfrom
NeloNew:fix/sentry-crm-38-opportunities-board-n1
Closed

Fix N+1 query in opportunities board#150
NeloNew wants to merge 1 commit intorelaticle:mainfrom
NeloNew:fix/sentry-crm-38-opportunities-board-n1

Conversation

@NeloNew
Copy link
Copy Markdown
Contributor

@NeloNew NeloNew commented Feb 23, 2026

Problem

Sentry detected an N+1 query issue (RELATICLE-CRM-38) when loading the opportunities board. The board was loading custom field values individually for each opportunity card.

Solution

Added ->withCustomFieldValues() to the board query to eager load all custom field relationships in a single query.

Performance Impact

  • Before: 10-20+ queries per page load (one per opportunity)
  • After: 1-3 queries total (batch loaded)

Related Issues

Testing

  • Board still loads correctly
  • Opportunities display with custom fields
  • No test regressions

NeloNew added a commit to NeloNew/relaticle that referenced this pull request Feb 23, 2026
Addresses Copilot's feedback on PR relaticle#146 by applying eager loading
optimization consistently across all resources that implement HasCustomFields.

Changes:
- Added ->withCustomFieldValues() to PeopleResource
- Added ->withCustomFieldValues() to CompanyResource
- Added ->withCustomFieldValues() to OpportunityResource
- Added ->withCustomFieldValues() to TaskResource
- Added ->withCustomFieldValues() to NoteResource

Performance impact:
- Before: 10-20+ queries per page load (one per record)
- After: 1-3 queries total (batch loaded)

Related:
- Supersedes PR relaticle#146 (PeopleResource only)
- Supersedes PR relaticle#150 (OpportunityResource only)
- Resolves RELATICLE-CRM-39
- Resolves RELATICLE-CRM-38

Tests: 722 passed, 5 skipped
@NeloNew
Copy link
Copy Markdown
Contributor Author

NeloNew commented Feb 23, 2026

Superseded by comprehensive fix in PR #151 which applies the N+1 optimization across all 5 resources (People, Company, Opportunity, Task, Note) as suggested by Copilot.

This ensures consistent performance optimization across all entity types that implement HasCustomFields.

@NeloNew NeloNew closed this Feb 23, 2026
ManukMinasyan pushed a commit that referenced this pull request Feb 23, 2026
Addresses Copilot's feedback on PR #146 by applying eager loading
optimization consistently across all resources that implement HasCustomFields.

Changes:
- Added ->withCustomFieldValues() to PeopleResource
- Added ->withCustomFieldValues() to CompanyResource
- Added ->withCustomFieldValues() to OpportunityResource
- Added ->withCustomFieldValues() to TaskResource
- Added ->withCustomFieldValues() to NoteResource

Performance impact:
- Before: 10-20+ queries per page load (one per record)
- After: 1-3 queries total (batch loaded)

Related:
- Supersedes PR #146 (PeopleResource only)
- Supersedes PR #150 (OpportunityResource only)
- Resolves RELATICLE-CRM-39
- Resolves RELATICLE-CRM-38

Tests: 722 passed, 5 skipped
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