Skip to content

Commit

Permalink
Reactivate lru cache for inherit_matching_entities
Browse files Browse the repository at this point in the history
  • Loading branch information
nuwang committed Sep 13, 2024
1 parent 0076bc3 commit e337fe3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tpv/core/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def __init__(self, loader: TPVConfigLoader):
self.default_inherits = self.config.global_config.default_inherits
self.global_context = self.config.global_config.context
self.lookup_tool_regex = functools.lru_cache(maxsize=None)(self.__compile_tool_regex)
# self.inherit_matching_entities = functools.lru_cache(maxsize=None)(self.__inherit_matching_entities)
self.inherit_matching_entities = self.__inherit_matching_entities
self.inherit_matching_entities = functools.lru_cache(maxsize=None)(self.__inherit_matching_entities)

def __compile_tool_regex(self, key):
try:
Expand All @@ -46,7 +45,8 @@ def _find_entities_matching_id(self, entity_list: dict[str, Entity], entity_name
matches.append(match)
return matches

def __inherit_matching_entities(self, entity_list: dict[str, Entity], entity_name: str):
def __inherit_matching_entities(self, entity_type: str, entity_name: str):
entity_list = getattr(self.config, entity_type)
matches = self._find_entities_matching_id(entity_list, entity_name)
return self.inherit_entities(matches)

Expand Down Expand Up @@ -97,22 +97,22 @@ def to_galaxy_destination(self, destination):
)

def _find_matching_entities(self, tool, user):
tool_entity = self.inherit_matching_entities(self.config.tools, tool.id)
tool_entity = self.inherit_matching_entities("tools", tool.id)
if not tool_entity:
tool_entity = Tool(loader=self.loader, id=tool.id)

entity_list = [tool_entity]

if user:
role_entities = (self.inherit_matching_entities(self.config.roles, role.name)
role_entities = (self.inherit_matching_entities("roles", role.name)
for role in user.all_roles() if not role.deleted)
# trim empty
user_role_entities = (role for role in role_entities if role)
user_role_entity = next(user_role_entities, None)
if user_role_entity:
entity_list += [user_role_entity]

user_entity = self.inherit_matching_entities(self.config.users, user.email)
user_entity = self.inherit_matching_entities("users", user.email)
if user_entity:
entity_list += [user_entity]

Expand Down

0 comments on commit e337fe3

Please sign in to comment.