Skip to content

Conversation

shaykeren
Copy link

@shaykeren shaykeren commented Jul 24, 2025

This PR addresses the N+1 query performance issue in the Vets endpoint by implementing several optimizations:

  1. Changed the specialties relationship in Vet entity to use FetchType.LAZY instead of EAGER to prevent unnecessary loading
  2. Added JOIN FETCH query in VetRepository to efficiently load vets with their specialties in a single query
  3. Added @EntityGraph for paginated queries to control fetch strategy
  4. Added database indexes on vet_id and specialty_id columns in the vet_specialties table
  5. Implemented query result caching using Spring's @Cacheable annotation

These changes should significantly improve the performance of the /vets.html endpoint by:

  • Reducing the number of database queries
  • Optimizing join operations with proper indexes
  • Caching frequently accessed data

Testing:

  • Verified that the changes maintain existing functionality
  • Confirmed that the N+1 query issue is resolved
  • Checked that indexes are properly created

Related issue: #93

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