Skip to content

Commit 3814c75

Browse files
authored
Merge pull request #391 from zigzagdev/chore/remove-image_url-from-qs-command
chore: remove runtime usage of image_url from commands and query services
2 parents 9dcfd6d + 483fe27 commit 3814c75

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/app/Console/Commands/AlgoliaImportWorldHeritages.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ public function handle(): int
5151

5252
WorldHeritage::query()
5353
->with([
54-
'countries',
54+
'images' => function ($query) {
55+
$query->where('is_primary', true)->select(['world_heritage_site_id', 'url']);
56+
},
57+
'countries' => function ($query) {
58+
$query->select(['countries.state_party_code', 'countries.name_en', 'countries.name_jp']);
59+
},
5560
])
5661
->select([
5762
'world_heritage_sites.id',
@@ -63,7 +68,6 @@ public function handle(): int
6368
'world_heritage_sites.category',
6469
'world_heritage_sites.year_inscribed',
6570
'world_heritage_sites.is_endangered',
66-
'world_heritage_sites.image_url',
6771
])
6872
->chunkById($chunk, function ($rows) use ($client, $indexName, $dryRun, &$processed) {
6973
$objects = [];
@@ -130,7 +134,7 @@ public function handle(): int
130134
'category' => (string) $row->category,
131135
'year_inscribed' => $row->year_inscribed !== null ? (int) $row->year_inscribed : null,
132136
'is_endangered' => (bool) $row->is_endangered,
133-
'thumbnail_url' => $row->image_url !== null ? (string) $row->image_url : null,
137+
'thumbnail_url' => $row->images->first()?->url,
134138
'state_party_codes' => $statePartyCodes,
135139
'country_names_jp' => $countryCount > 1 ? $countryNamesJp : [],
136140
];

src/app/Console/Commands/ImportWorldHeritageSiteFromSplitFile.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public function handle(): int
9696
'latitude' => $this->toNullableFloat($row['latitude'] ?? null),
9797
'longitude' => $this->toNullableFloat($row['longitude'] ?? null),
9898
'short_description' => $this->toNullableString($row['short_description'] ?? null),
99-
'image_url' => $this->toNullableString($row['image_url'] ?? null),
10099
'unesco_site_url' => $this->toNullableString($row['unesco_site_url'] ?? null),
101100
'created_at' => $now,
102101
'updated_at' => $now,

src/app/Packages/Domains/WorldHeritageReadQueryService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ public function findByIdsPreserveOrder(array $ids): Collection
3333
'world_heritage_sites.latitude',
3434
'world_heritage_sites.longitude',
3535
'world_heritage_sites.short_description',
36-
'world_heritage_sites.image_url',
3736
])
3837
->with([
3938
'countries' => function ($q) {
4039
$q->select('countries.state_party_code', 'countries.name_en', 'countries.name_jp', 'countries.region')
4140
->orderBy('countries.state_party_code', 'asc');
4241
},
42+
'images' => function ($imageQuery) {
43+
$imageQuery->where('is_primary', true)->limit(1);
44+
},
4345
])
4446
->whereIn('world_heritage_sites.id', $ids)
4547
->get()

0 commit comments

Comments
 (0)