Goal
Confirm there are no N+1 query patterns lurking in the list or search code paths that multiply DB queries proportionally with the number of results returned.
What to Do
- Install / enable Laravel Debugbar or Telescope locally and load the list endpoint with
per_page=20.
- Record total query count. Expected: 1 main query + 1 per eager-loaded relation (countries, images, descriptions) = ~4 total. Any more indicates N+1.
- If N+1 is found, fix with
->with([...]) eager loading or ->withCount(...) on the Eloquent query. Do NOT use lazy loading inside loops.
- Check
buildWorldHeritagePayload() — it accesses $heritage->countries, $heritage->images, $heritage->descriptions per row. Confirm these are already loaded via eager loading and not triggering additional queries.
- Check the search path:
searchHeritages() calls findByIdsPreserveOrder() — confirm this also eager-loads relations in a single batch.
Acceptance Criteria
- Total query count for a list page request ≤ 5 (regardless of page size)
- No query count grows linearly with
per_page
- Profiling results (query count before/after) documented in the PR
Parent Issue
Related: #457
Goal
Confirm there are no N+1 query patterns lurking in the list or search code paths that multiply DB queries proportionally with the number of results returned.
What to Do
per_page=20.->with([...])eager loading or->withCount(...)on the Eloquent query. Do NOT use lazy loading inside loops.buildWorldHeritagePayload()— it accesses$heritage->countries,$heritage->images,$heritage->descriptionsper row. Confirm these are already loaded via eager loading and not triggering additional queries.searchHeritages()callsfindByIdsPreserveOrder()— confirm this also eager-loads relations in a single batch.Acceptance Criteria
per_pageParent Issue
Related: #457