image repairment in own products

This commit is contained in:
sriram
2026-09-04 15:44:07 +05:30
parent 8059120ce3
commit bb30edaffa
4 changed files with 3054 additions and 6 deletions

View File

@@ -576,14 +576,36 @@ def repair(cur, conn, brands: List[str], apply: bool, timeout: int, workers: int
# three providers were caught serving a confidently wrong image.
# --recheck re-opens rows whose stored URL names neither the brand
# nor any distinctive word of the product, so they are re-searched
# under the corroboration rule rather than grandfathered in.
# under the corroboration rule rather than grandfathered in - and,
# for the produce bucket, any row that simply is not the reviewed
# image (see below).
have = {r["image_id"] for r in needs}
for row in rows:
if row["image_id"] in have:
continue
name = row.get("product_name") or ""
# A REVIEWED IMAGE OUTRANKS THE HEURISTIC.
#
# The corroboration test below asks whether the URL contains a
# distinctive word of the product, and it cannot tell an image OF
# the thing from an image merely NAMED after it. It passed, and so
# grandfathered in, `Bitter_Gourd_Curry.jpg` for Bitter Gourd,
# `Zunaid_Ahmed_Palak.jpg` - a photograph of a person - for Palak,
# and `BANANA_CREPE_CON_BASIL_LEAVES.jpg` for Basil Leaves. That
# left 57 rows untouched on the first full run.
#
# Where a person has already chosen the image, no heuristic gets a
# vote: if the stored URL is not the curated one, it is wrong.
if _is_own_products(suffix):
curated = produce_reference.image_url(name)
if curated and (row.get("image_url") or "") != curated:
needs.append(row)
continue
stored = _row_urls(row)
if stored and not any(
_names_product(u, row.get("product_name") or "", suffix) for u in stored
_names_product(u, name, suffix) for u in stored
):
needs.append(row)
totals["scanned"] += len(rows)