From 0122fd2b0c1d75f91c8ee3540210e1ce16483d9d Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 17 Sep 2025 14:38:41 +0300 Subject: [PATCH] optimize product enrichment by avoiding duplicate product processing --- app/mongo.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/mongo.py b/app/mongo.py index 77f0634..c138482 100644 --- a/app/mongo.py +++ b/app/mongo.py @@ -293,7 +293,11 @@ async def additional_deals_data(*deals: dict, full: bool): deal["services"] = enriched_services enriched_products = [] + selected = set() for product in deal.get("products", []): + product_id = product["productId"] + if product_id in selected: + continue if full: 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) product["services"] = enriched_services + selected.add(product_id) + enriched_products.append(product) total_products += product.get("quantity", 1)