Issue Description
The Vets endpoint (/vets.html) is experiencing an N+1 query performance issue due to eager loading of specialties for each vet.
Root Cause
- The
Vet entity uses FetchType.EAGER for specialties, causing unnecessary queries
- Missing proper join fetching strategy in the repository layer
- No composite index on the
vet_specialties table for optimized joins
Solution
A pull request (#81) has been created with the following changes:
- Changed
FetchType.EAGER to FetchType.LAZY in the Vet entity
- Added
@NamedEntityGraph for efficient fetching of Vet specialties
- Updated VetRepository to use
@EntityGraph annotation
- Added composite index on
vet_specialties(vet_id, specialty_id)
Impact
These changes will:
- Prevent unnecessary queries when specialties are not needed
- Optimize fetching when specialties are needed using join fetch
- Improve query performance with proper indexing
Testing
- The changes maintain existing functionality while improving performance
- The EntityGraph ensures efficient loading of specialties when needed
- The composite index will improve join performance
Related
Issue Description
The Vets endpoint (
/vets.html) is experiencing an N+1 query performance issue due to eager loading of specialties for each vet.Root Cause
Vetentity usesFetchType.EAGERfor specialties, causing unnecessary queriesvet_specialtiestable for optimized joinsSolution
A pull request (#81) has been created with the following changes:
FetchType.EAGERtoFetchType.LAZYin the Vet entity@NamedEntityGraphfor efficient fetching of Vet specialties@EntityGraphannotationvet_specialties(vet_id, specialty_id)Impact
These changes will:
Testing
Related