diff --git a/src/recommendationservice/recommendation_server.py b/src/recommendationservice/recommendation_server.py index 1ea14f5..b75c3a0 100644 --- a/src/recommendationservice/recommendation_server.py +++ b/src/recommendationservice/recommendation_server.py @@ -12,13 +12,17 @@ class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer): # fetch list of products from product catalog stub cat_response = stub.ListProducts(demo_pb2.Empty()) - num_prodcuts = len(cat_response.products) - num_return = min(max_responses, num_prodcuts) + + product_ids = [x.id for x in cat_response.products] + filtered_products = list(set(product_ids)-set(request.product_ids)) + + num_products = len(filtered_products) + num_return = min(max_responses, num_products) # sample list of indicies to return - indices = random.sample(range(num_prodcuts), num_return) + indices = random.sample(range(num_products), num_return) # fetch product ids from indices - prod_list = [cat_response.products[i].id for i in indices] + prod_list = [filtered_products[i] for i in indices] print("handling request: {}".format(prod_list)) # build and return response