From e640123d494d49d06ffdaf9b6d2921b342647157 Mon Sep 17 00:00:00 2001 From: Robi9 Date: Wed, 8 Nov 2023 14:27:37 -0300 Subject: [PATCH] Remove product duplicates --- services/external/weni/service.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/external/weni/service.go b/services/external/weni/service.go index f9a14da23..aa28f99be 100644 --- a/services/external/weni/service.go +++ b/services/external/weni/service.go @@ -99,6 +99,7 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log } productRetailerIDS := []string{} + productRetailerIDMap := make(map[string]struct{}) for _, product := range productList { searchResult, trace, err := GetProductListFromSentenX(product, catalog.FacebookCatalogID(), searchThreshold, s.rtConfig) @@ -107,7 +108,12 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log return callResult, errors.Wrapf(err, "on iterate to search products on sentenx") } for _, prod := range searchResult { - productRetailerIDS = append(productRetailerIDS, prod["product_retailer_id"]) + productRetailerID := prod["product_retailer_id"] + _, exists := productRetailerIDMap[productRetailerID] + if !exists { + productRetailerIDS = append(productRetailerIDS, productRetailerID) + productRetailerIDMap[productRetailerID] = struct{}{} + } } }