Skip to content

Commit

Permalink
Updated caching to consider the retrofit_key entry when matching the …
Browse files Browse the repository at this point in the history
…cache
  • Loading branch information
navarroc committed Mar 7, 2024
1 parent bfbca79 commit 78eb594
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pyincore/dfr3service.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def match_inventory(self, mapping: MappingSet, inventories: list, entry_key: Opt
# if retrofit key exist, use retrofit key otherwise use default key
retrofit_entry_key = inventory["properties"]["retrofit_k"] if "retrofit_k" in \
inventory["properties"] else None

cached_curve = self._check_cache(dfr3_sets_cache, inventory["properties"])

if cached_curve is not None:
Expand All @@ -234,6 +234,9 @@ def match_inventory(self, mapping: MappingSet, inventories: list, entry_key: Opt
dfr3_sets[inventory['id']] = curve

matched_properties_dict = self._convert_properties_to_dict(m.rules, inventory["properties"])

if retrofit_entry_key is not None:
matched_properties_dict["retrofit_k"] = retrofit_entry_key
# Add the matched inventory properties so other matching inventory can avoid rule matching
dfr3_sets_cache[curve] = matched_properties_dict

Expand Down Expand Up @@ -364,12 +367,16 @@ def _check_cache(dfr3_sets_dict, properties):
if not dfr3_sets_dict:
return None

retrofit_entry_key = properties["retrofit_k"] if "retrofit_k" in properties else None
for entry_key in dfr3_sets_dict:
inventory_dict = {}
entry_dict = dfr3_sets_dict[entry_key]
for rule_key in entry_dict:
inventory_dict[rule_key] = properties[rule_key]

if retrofit_entry_key is not None:
inventory_dict["retrofit_k"] = retrofit_entry_key

if entry_dict == inventory_dict:
return entry_key

Expand Down

0 comments on commit 78eb594

Please sign in to comment.