chore: remove runtime usage of image_url from commands and query services#391
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes runtime dependencies on the legacy world_heritage_sites.image_url column by switching reads/exports/imports to use world_heritage_site_images (via the images relation), as preparation for dropping the column.
Changes:
- Removed
world_heritage_sites.image_urlfrom select clauses and switched to eager-loading primary images. - Updated Algolia indexing to source
thumbnail_urlfrom the primary image relation instead of the legacy column. - Removed
image_urlfrom the upsert payload when importing split site JSON.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/app/Packages/Domains/WorldHeritageReadQueryService.php |
Drops image_url selection and eager-loads primary images when fetching sites by IDs. |
src/app/Console/Commands/ImportWorldHeritageSiteFromSplitFile.php |
Stops writing image_url into world_heritage_sites during split-file imports. |
src/app/Console/Commands/AlgoliaImportWorldHeritages.php |
Indexes Algolia thumbnail_url from world_heritage_site_images instead of the legacy column. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ->orderBy('countries.state_party_code', 'asc'); | ||
| }, | ||
| 'images' => function ($imageQuery) { | ||
| $imageQuery->where('is_primary', true)->limit(1); |
There was a problem hiding this comment.
limit(1) inside a HasMany eager-load constraint will apply to the entire eager-load query, not per world_heritage_site_id. This can result in only one primary image being loaded across all returned sites, leaving the rest with an empty images relation. Prefer removing the limit(1) (and rely on is_primary uniqueness), or introduce a dedicated hasOne/ofMany relation like primaryImage and eager-load that instead.
| $imageQuery->where('is_primary', true)->limit(1); | |
| $imageQuery->where('is_primary', true); |
| ->orderBy('countries.state_party_code', 'asc'); | ||
| }, | ||
| 'images' => function ($imageQuery) { | ||
| $imageQuery->where('is_primary', true)->limit(1); |
There was a problem hiding this comment.
There’s no test coverage asserting that findByIdsPreserveOrder() returns the expected primary image per site (especially when multiple site IDs are requested). Given the eager-load constraint on images, adding a test that seeds images for at least 2 sites and verifies each model has its primary image loaded would prevent regressions and catch issues like global eager-load limits.
| $imageQuery->where('is_primary', true)->limit(1); | |
| $imageQuery->where('is_primary', true); |
| $query->where('is_primary', true)->select(['world_heritage_site_id', 'url']); | ||
| }, | ||
| 'countries' => function ($query) { | ||
| $query->select(['countries.state_party_code', 'countries.name_en', 'countries.name_jp']); |
There was a problem hiding this comment.
The countries relation here is used to build arrays that are sent to Algolia. Without an explicit ordering, the DB may return countries in a non-deterministic order, which can cause unnecessary Algolia updates (array order changes) and make results harder to reason about. Consider adding an orderBy('countries.state_party_code') (or another stable key) in this eager-load constraint.
| $query->select(['countries.state_party_code', 'countries.name_en', 'countries.name_jp']); | |
| $query->select(['countries.state_party_code', 'countries.name_en', 'countries.name_jp']) | |
| ->orderBy('countries.state_party_code'); |
What
Why
Removes all runtime references to world_heritage_sites.image_url
in preparation for dropping the column (#300-3).
Images are now sourced exclusively from world_heritage_site_images.