Fix N+1 queries across all custom field resources#151
Merged
ManukMinasyan merged 1 commit intorelaticle:mainfrom Feb 23, 2026
Merged
Conversation
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
This was referenced Feb 23, 2026
ManukMinasyan
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Copilot identified in PR #146 that the N+1 query optimization should be applied consistently across all resources that implement
HasCustomFields, not just PeopleResource.When displaying records with custom fields, values were being loaded individually in a loop, causing up to 10-20 separate database queries per page load.
Solution
Added eager loading to all 5 resources using the existing
withCustomFieldValues()scope:✅ PeopleResource - Loads custom field relationships in batch
✅ CompanyResource - Loads custom field relationships in batch
✅ OpportunityResource - Loads custom field relationships in batch
✅ TaskResource - Loads custom field relationships in batch
✅ NoteResource - Loads custom field relationships in batch
This ensures consistent performance optimization across all entity types.
Performance Impact
Before:
After:
Testing
✅ All 722 tests passing (151s duration)
✅ No regressions detected
✅ Eager loading applied consistently to all resources
Related Issues
Files Changed