Problem
Both getAllHeritages() and findByIdsPreserveOrder() eager-load the images relation:
'images' => static function ($imagesQuery): void {
$imagesQuery->where('is_primary', true)->limit(1);
},
Since main_image_url was added directly to world_heritage_sites, the thumbnail_url fallback chain is:
// WorldHeritageViewModel::getThumbnailUrl()
return $this->dto->getMainImageUrl() ?? ($this->dto->getImages()[0]['url'] ?? null);
For the vast majority of sites main_image_url is non-null, so the images relation result is never used. This is an unnecessary extra query on every list page load and every Algolia search result.
Fix
Remove the images eager load block from:
WorldHeritageQueryService::getAllHeritages()
WorldHeritageReadQueryService::findByIdsPreserveOrder()
The getHeritageById() detail endpoint should keep its images eager load (it renders the full image gallery).
Expected Impact
- Eliminates 1 extra query per list/search request
- No change to API response shape —
thumbnail_url still resolves from main_image_url
Parent Issue
Part of #463
Problem
Both
getAllHeritages()andfindByIdsPreserveOrder()eager-load theimagesrelation:Since
main_image_urlwas added directly toworld_heritage_sites, thethumbnail_urlfallback chain is:For the vast majority of sites
main_image_urlis non-null, so the images relation result is never used. This is an unnecessary extra query on every list page load and every Algolia search result.Fix
Remove the
imageseager load block from:WorldHeritageQueryService::getAllHeritages()WorldHeritageReadQueryService::findByIdsPreserveOrder()The
getHeritageById()detail endpoint should keep its images eager load (it renders the full image gallery).Expected Impact
thumbnail_urlstill resolves frommain_image_urlParent Issue
Part of #463