Skip to content

Commit

Permalink
Merge pull request #53 from weni-ai/feat/duplicate-products
Browse files Browse the repository at this point in the history
Remove duplicate products for catalog messages
  • Loading branch information
Robi9 authored Nov 8, 2023
2 parents c5248f3 + e640123 commit e18b850
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion services/external/weni/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{}{}
}
}
}

Expand Down

0 comments on commit e18b850

Please sign in to comment.