This commit is contained in:
2026-08-22 19:23:15 +02:00
parent 0c154254c3
commit bd762d1ccf
21 changed files with 1047 additions and 111 deletions
+31 -1
View File
@@ -673,7 +673,7 @@ const (
processedPreferredDescriptionSQL = `COALESCE(NULLIF(p.processed_description, ''), NULLIF(p.description, ''), NULLIF(r.mapped_data->>'description', ''), '')`
processedHasNameSQL = `(` + processedPreferredNameSQL + ` <> '')`
processedHasDescriptionSQL = `(` + processedPreferredDescriptionSQL + ` <> '')`
processedHasCategorySQL = `(COALESCE(NULLIF(p.category, ''), '') <> '' AND lower(p.category) <> 'none')`
processedHasCategorySQL = `(COALESCE(NULLIF(p.category, ''), '') <> '' AND lower(p.category) <> 'none')`
// Resolve display name / canonical unique_id when products store unique_id, UUID id, or name.
processedCategoryResolveJoin = `
LEFT JOIN LATERAL (
@@ -770,8 +770,34 @@ var (
OR COALESCE(NULLIF(trim(r.mapped_data->>'eprel'), ''), '') <> ''
OR COALESCE(NULLIF(trim(r.mapped_data->>'EPRELID'), ''), '') <> ''
)`
// listMainImageSQL is the first usable image URL for a product row, so the list
// can show a thumbnail without shipping the whole mapped_data blob per row.
//
// Key order mirrors catalog.ExtractProductImages (raw_v1.go) and
// productImageUrls (apps/web/src/lib/product-images.ts): main_image is often an
// empty string while `moreimages` / `additional_image_urls` hold a comma-joined
// list, so those are split on the first entry. `%s` is the mapped_data column ref.
listMainImageTemplate = `COALESCE(
NULLIF(trim(%[1]s->>'image_url'), ''),
NULLIF(trim(%[1]s->>'main_image'), ''),
NULLIF(trim(%[1]s->>'image_link'), ''),
NULLIF(trim(%[1]s->>'mainImage'), ''),
NULLIF(trim(%[1]s->>'imageUrl'), ''),
NULLIF(trim(%[1]s->'images'->>0), ''),
NULLIF(trim(split_part(%[1]s->>'moreimages', ',', 1)), ''),
NULLIF(trim(split_part(%[1]s->>'more_images', ',', 1)), ''),
NULLIF(trim(split_part(%[1]s->>'additional_image_urls', ',', 1)), ''),
NULLIF(trim(split_part(%[1]s->>'additional_image_link', ',', 1)), '')
)`
)
// listMainImageSQL renders listMainImageTemplate for a mapped_data column reference
// ("rp.mapped_data" on the raw list, "r.mapped_data" on the processed join).
func listMainImageSQL(mappedDataRef string) string {
return fmt.Sprintf(listMainImageTemplate, mappedDataRef)
}
func normalizeCoverageFilter(raw string) string {
c := strings.ToLower(strings.TrimSpace(raw))
c = strings.ReplaceAll(c, "-", "_")
@@ -958,6 +984,7 @@ func (s *Service) ListRawProducts(ctx context.Context, companyID uuid.UUID, f Li
(COALESCE(NULLIF(trim(rp.mapped_data->>'description'), ''), '') <> '') AS has_description,
(COALESCE(NULLIF(trim(rp.mapped_data->>'category'), ''), '') <> '' AND lower(trim(rp.mapped_data->>'category')) <> 'none') AS has_category,
`+strings.ReplaceAll(processedHasFeedAttributesSQL, "r.mapped_data", "rp.mapped_data")+` AS has_attributes,
`+listMainImageSQL("rp.mapped_data")+` AS main_image,
rp.created_at, rp.updated_at
%s%s WHERE %s
ORDER BY %s
@@ -971,6 +998,7 @@ func (s *Service) ListRawProducts(ctx context.Context, companyID uuid.UUID, f Li
"name", "category", "category_name", "category_unique_id",
"feed_name", "sync_changes",
"has_name", "has_description", "has_category", "has_attributes",
"main_image",
"created_at", "updated_at",
})
},
@@ -1113,6 +1141,7 @@ func (s *Service) ListProcessedProducts(ctx context.Context, companyID uuid.UUID
`+processedHasAttributesSQL+` AS has_attributes,
`+processedHasProcessedAttributesSQL+` AS has_processed_attributes,
`+processedHasEprelSQL+` AS has_eprel,
`+listMainImageSQL("r.mapped_data")+` AS main_image,
p.created_at, p.updated_at
FROM processed_products p
LEFT JOIN raw_products r ON r.id = p.raw_product_id
@@ -1129,6 +1158,7 @@ func (s *Service) ListProcessedProducts(ctx context.Context, companyID uuid.UUID
"feed_name", "feed_last_synced_at", "raw_updated_at",
"has_name", "has_processed_name", "has_description", "has_processed_description", "has_category", "has_attributes", "has_processed_attributes",
"has_eprel",
"main_image",
"created_at", "updated_at",
})
if err != nil {