@@ -53,7 +53,14 @@ def _serialize_data(cls, data):
53
53
54
54
@classmethod
55
55
def _deserialize_data (cls , raw ):
56
- return json .loads (raw .decode ("utf-8" ))
56
+ # The scores that are inserted into Redis are actually 1/score. On the other hand, we
57
+ # have securities which have their score set to 0. When that happens, we store the score
58
+ # as inf, which Redis knows about and can handle, but the JSON spec does not so we get
59
+ # an error when trying to deserialize it.
60
+ # Here, we check to see if the redis stored value is b"inf" and only deserialize it when it's
61
+ # not. If it is, we leave it as "inf"
62
+
63
+ return json .loads (raw .decode ("utf-8" )) if raw != b"inf" else "inf"
57
64
58
65
@staticmethod
59
66
def _get_prefixes_set (norm_terms_list ):
@@ -1249,14 +1256,7 @@ def _facet_list_to_set(facet_list):
1249
1256
scores_map_key = SCORE_MAP_BASE_NAME % provider_name
1250
1257
scores_db_map = {}
1251
1258
for obj_id , score in REDIS .hgetall (scores_map_key ).items ():
1252
- # The scores that are inserted into Redis are actually 1/score. On the other hand, we
1253
- # have securities which have their score set to 0. When that happens, we store the score
1254
- # as inf, which Redis knows about and can handle, but the JSON spec does not so we get
1255
- # an error when trying to deserialize it.
1256
- # Here, we check to see if the redis stored is b"inf" and only deserialize it when it's
1257
- # not. If it is, we leave it as "inf" because later we convert it into float and can
1258
- # handle it normally
1259
- parsed_score = self ._deserialize_data (score ) if score != b"inf" else "inf"
1259
+ parsed_score = self ._deserialize_data (score )
1260
1260
obj_id = str (obj_id .decode ("utf-8" ))
1261
1261
scores_db_map [obj_id ] = float (parsed_score )
1262
1262
@@ -1294,12 +1294,15 @@ def _facet_list_to_set(facet_list):
1294
1294
if len (term .split (" " )) <= max_word_count :
1295
1295
exact_sorted_set_key = EXACT_BASE_NAME % (provider_name , term )
1296
1296
pipe .zadd (exact_sorted_set_key , {obj_id : scores_live_map [obj_id ]})
1297
- self .log .info (f"Added 1 entry to { exact_sorted_set_key } " )
1298
- # Terms in the DB but not in the live set are terms that got removed
1299
- for term in db_obj_terms - live_obj_terms :
1297
+ self .log .info (f"Added { len (terms_to_add )} entries to { EXACT_BASE_NAME } " )
1298
+ # Terms in tterms_to_removehe DB but not in the live set are terms that got removed
1299
+ terms_to_remove = db_obj_terms - live_obj_terms
1300
+ for term in terms_to_remove :
1300
1301
exact_sorted_set_key = EXACT_BASE_NAME % (provider_name , term )
1301
1302
pipe .zrem (exact_sorted_set_key , obj_id )
1302
- self .log .info (f"Removed 1 entry from { exact_sorted_set_key } " )
1303
+ self .log .info (
1304
+ f"Removed { len (terms_to_remove )} entries from { EXACT_BASE_NAME } "
1305
+ )
1303
1306
1304
1307
# Repeat the same logic for prefixes
1305
1308
live_obj_prefixes = frozenset (
@@ -1318,13 +1321,16 @@ def _facet_list_to_set(facet_list):
1318
1321
for prefix in prefixes_to_add :
1319
1322
prefix_sorted_set_key = PREFIX_BASE_NAME % (provider_name , prefix )
1320
1323
pipe .zadd (prefix_sorted_set_key , {obj_id : scores_live_map [obj_id ]})
1321
- self .log .info (f"Added 1 entry to { prefix_sorted_set_key } " )
1324
+ self .log .info (f"Added { len ( prefixes_to_add ) } entries to { PREFIX_BASE_NAME } " )
1322
1325
1323
1326
# Prefixes in the DB but not in the live set are prefixes that got removed
1324
- for prefix in db_obj_prefixes - live_obj_prefixes :
1327
+ prefixes_to_remove = db_obj_prefixes - live_obj_prefixes
1328
+ for prefix in prefixes_to_remove :
1325
1329
prefix_sorted_set_key = PREFIX_BASE_NAME % (provider_name , prefix )
1326
1330
pipe .zrem (prefix_sorted_set_key , obj_id )
1327
- self .log .info (f"Removed 1 entry to { prefix_sorted_set_key } " )
1331
+ self .log .info (
1332
+ f"Removed { len (prefixes_to_remove )} entries to { PREFIX_BASE_NAME } "
1333
+ )
1328
1334
1329
1335
# Update exact terms sets
1330
1336
# Build a single set of all terms in each data set
@@ -1391,11 +1397,14 @@ def _facet_list_to_set(facet_list):
1391
1397
for key , value in facets_to_add :
1392
1398
facet_sorted_set_key = FACET_SET_BASE_NAME % (provider_name , key , value )
1393
1399
pipe .zadd (facet_sorted_set_key , {obj_id : scores_live_map [obj_id ]})
1394
- self .log .info (f"Added 1 entry to { facet_sorted_set_key } " )
1395
- for key , value in db_obj_facets - live_obj_facets :
1400
+ self .log .info (f"Added { len (facets_to_add )} entries to { FACET_BASE_NAME } " )
1401
+ facets_to_remove = db_obj_facets - live_obj_facets
1402
+ for key , value in facets_to_remove :
1396
1403
facet_sorted_set_key = FACET_SET_BASE_NAME % (provider_name , key , value )
1397
1404
pipe .zrem (facet_sorted_set_key , obj_id )
1398
- self .log .info (f"Removed 1 entry to { facet_sorted_set_key } " )
1405
+ self .log .info (
1406
+ f"Removed { len (facets_to_remove )} entries to { FACET_SET_BASE_NAME } "
1407
+ )
1399
1408
1400
1409
# Bulk update the facets hash map with all needed facets in a single operation
1401
1410
if facets_with_updates := facets_live_set - facets_db_set :
@@ -1439,10 +1448,10 @@ def _facet_list_to_set(facet_list):
1439
1448
obj_id : scores_live_map [obj_id ] for obj_id in objs_with_updated_scores
1440
1449
}:
1441
1450
pipe .hset (scores_map_key , mapping = updated_scores )
1442
- self .log .info (f"Added { len (updated_scores )} entries to { updated_scores } " )
1451
+ self .log .info (f"Added { len (updated_scores )} entries to { scores_map_key } " )
1443
1452
if objs_removed := set (scores_db_map .keys ()) - set (scores_live_map .keys ()):
1444
1453
pipe .hdel (scores_map_key , * objs_removed )
1445
- self .log .info (f"Removed { len (objs_removed )} entries from { objs_removed } " )
1454
+ self .log .info (f"Removed { len (objs_removed )} entries from { scores_map_key } " )
1446
1455
# Execute all the additions and deletions in a single connection
1447
1456
pipe .execute ()
1448
1457
self .log .info (f"End update of provider { provider_name } " )
0 commit comments