optimize product enrichment by avoiding duplicate product processing
This commit is contained in:
@ -293,7 +293,11 @@ async def additional_deals_data(*deals: dict, full: bool):
|
|||||||
deal["services"] = enriched_services
|
deal["services"] = enriched_services
|
||||||
|
|
||||||
enriched_products = []
|
enriched_products = []
|
||||||
|
selected = set()
|
||||||
for product in deal.get("products", []):
|
for product in deal.get("products", []):
|
||||||
|
product_id = product["productId"]
|
||||||
|
if product_id in selected:
|
||||||
|
continue
|
||||||
if full:
|
if full:
|
||||||
product["product"] = products.get(product["productId"])
|
product["product"] = products.get(product["productId"])
|
||||||
|
|
||||||
@ -305,6 +309,8 @@ async def additional_deals_data(*deals: dict, full: bool):
|
|||||||
total_price += service.get("price", 0) * service.get("quantity", 1) * product.get("quantity", 1)
|
total_price += service.get("price", 0) * service.get("quantity", 1) * product.get("quantity", 1)
|
||||||
|
|
||||||
product["services"] = enriched_services
|
product["services"] = enriched_services
|
||||||
|
selected.add(product_id)
|
||||||
|
|
||||||
enriched_products.append(product)
|
enriched_products.append(product)
|
||||||
|
|
||||||
total_products += product.get("quantity", 1)
|
total_products += product.get("quantity", 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user