3737)
3838
3939
40- cached_ids = []
41- cached_ids_to_retrieve_recommendations_for = []
42- MAX_CACHED_IDS = 2000000
43-
4440first_run = True
4541
4642class RecommendationService (demo_pb2_grpc .RecommendationServiceServicer ):
@@ -67,31 +63,6 @@ def Watch(self, request, context):
6763 return health_pb2 .HealthCheckResponse (
6864 status = health_pb2 .HealthCheckResponse .UNIMPLEMENTED )
6965
70- def get_recommendations_ids (request_product_ids ):
71- global cached_ids
72-
73- with tracer .start_as_current_span ("get_recommendations_ids" ) as span :
74- can_retrieve_from_cache = True
75- for p_id in request_product_ids :
76- if p_id not in cached_ids_to_retrieve_recommendations_for :
77- can_retrieve_from_cache = False
78-
79- if not can_retrieve_from_cache :
80- logger .info ("get_recommendations_ids: cache miss" )
81- span .set_attribute ("app.cache_hit" , False )
82- cat_response = product_catalog_stub .ListProducts (demo_pb2 .Empty ())
83- ids_to_add = []
84- for x in cat_response .products :
85- ids_to_add .extend (cached_ids )
86- ids_to_add .append (x .id )
87- if len (ids_to_add ) + len (cached_ids ) < MAX_CACHED_IDS :
88- cached_ids = cached_ids + ids_to_add
89- return cached_ids
90- else :
91- logger .info ("get_recommendations_ids: cache hit" )
92- span .set_attribute ("app.cache_hit" , True )
93- return cached_ids
94-
9566def get_product_list (request_product_ids ):
9667 global first_run
9768 with tracer .start_as_current_span ("get_product_list" ) as span :
@@ -101,7 +72,8 @@ def get_product_list(request_product_ids):
10172 request_product_ids_str = '' .join (request_product_ids )
10273 request_product_ids = request_product_ids_str .split (',' )
10374
104- product_ids = get_recommendations_ids (request_product_ids )
75+ cat_response = product_catalog_stub .ListProducts (demo_pb2 .Empty ())
76+ product_ids = [x .id for x in cat_response .products ]
10577
10678 span .set_attribute ("app.products.count" , len (product_ids ))
10779
0 commit comments