Skip to content

Remove unnecessary images eager load from list and search endpoints #465

@zigzagdev

Description

@zigzagdev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions