Skip to content

chore: remove runtime usage of image_url from commands and query services#391

Merged
zigzagdev merged 1 commit intofeat/clean-up-codefrom
chore/remove-image_url-from-qs-command
Mar 29, 2026
Merged

chore: remove runtime usage of image_url from commands and query services#391
zigzagdev merged 1 commit intofeat/clean-up-codefrom
chore/remove-image_url-from-qs-command

Conversation

@zigzagdev
Copy link
Copy Markdown
Owner

What

  • AlgoliaImportWorldHeritages: replace image_url select with images eager load, fix countries relation
  • WorldHeritageReadQueryService: remove image_url select, add images eager load
  • ImportWorldHeritageSiteFromSplitFile: remove image_url from upsert payload

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.

@zigzagdev zigzagdev requested a review from Copilot March 29, 2026 06:01
@zigzagdev zigzagdev self-assigned this Mar 29, 2026
Copy link
Copy Markdown
Owner Author

@zigzagdev zigzagdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@zigzagdev zigzagdev merged commit 3814c75 into feat/clean-up-code Mar 29, 2026
27 checks passed
@zigzagdev zigzagdev deleted the chore/remove-image_url-from-qs-command branch March 29, 2026 06:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_url from select clauses and switched to eager-loading primary images.
  • Updated Algolia indexing to source thumbnail_url from the primary image relation instead of the legacy column.
  • Removed image_url from 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);
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$imageQuery->where('is_primary', true)->limit(1);
$imageQuery->where('is_primary', true);

Copilot uses AI. Check for mistakes.
->orderBy('countries.state_party_code', 'asc');
},
'images' => function ($imageQuery) {
$imageQuery->where('is_primary', true)->limit(1);
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$imageQuery->where('is_primary', true)->limit(1);
$imageQuery->where('is_primary', true);

Copilot uses AI. Check for mistakes.
$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']);
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$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');

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: remove runtime usage of image_url from commands and query services

2 participants