Skip to content

Commit

Permalink
Adding caches to other list_agents subtasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Rodgers committed Apr 23, 2024
1 parent a0fe204 commit 103758a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions volttron/platform/aip.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ def __init__(self, env, **kwargs):
self.rmq_mgmt = RabbitMQMgmt()
self.instance_name = get_platform_instance_name()
self.agent_uuid_name_map = {}
self.agent_uuid_tag_map = {}
self.agent_uuid_id_map = {}
self.agent_uuid_priority_map = {}


def add_agent_user_group(self):
Expand Down Expand Up @@ -767,18 +770,26 @@ def agent_identity(self, agent_uuid):
@param agent_uuid:
@return:
"""
if cached_identity := self.agent_uuid_id_map.get(agent_uuid):
return cached_identity
if '/' in agent_uuid or agent_uuid in ['.', '..']:
raise ValueError('invalid agent')
identity_file = os.path.join(self.install_dir, agent_uuid, 'IDENTITY')
with ignore_enoent, open(identity_file, 'rt') as file:
return file.readline(64)
identity = file.readline(64)
self.agent_uuid_id_map[agent_uuid] = identity
return identity

def agent_tag(self, agent_uuid):
if cached_tag := self.agent_uuid_tag_map.get(agent_uuid):
return cached_tag
if '/' in agent_uuid or agent_uuid in ['.', '..']:
raise ValueError('invalid agent')
tag_file = os.path.join(self.install_dir, agent_uuid, 'TAG')
with ignore_enoent, open(tag_file, 'r') as file:
return file.readline(64)
tag = file.readline(64)
cached_tag[agent_uuid] = tag
return tag

def agent_version(self, agent_uuid):
if '/' in agent_uuid or agent_uuid in ['.', '..']:
Expand All @@ -805,9 +816,13 @@ def agent_versions(self):
return agents

def _agent_priority(self, agent_uuid):
if cached_priority := self.agent_uuid_priority_map.get(agent_uuid):
return cached_priority
autostart = os.path.join(self.install_dir, agent_uuid, 'AUTOSTART')
with ignore_enoent, open(autostart) as file:
return file.readline(100).strip()
priority = file.readline(100).strip()
self.agent_uuid_priority_map[agent_uuid] = priority
return priority

def agent_priority(self, agent_uuid):
if '/' in agent_uuid or agent_uuid in ['.', '..']:
Expand Down

0 comments on commit 103758a

Please sign in to comment.