mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Optimizing groups_for_host() lookup in inventory
This commit is contained in:
parent
fe892fccb1
commit
aa261bdd14
1 changed files with 5 additions and 7 deletions
|
@ -206,7 +206,7 @@ class Inventory(object):
|
||||||
pattern_exclude.append(p)
|
pattern_exclude.append(p)
|
||||||
elif p.startswith("&"):
|
elif p.startswith("&"):
|
||||||
pattern_intersection.append(p)
|
pattern_intersection.append(p)
|
||||||
else:
|
elif p:
|
||||||
pattern_regular.append(p)
|
pattern_regular.append(p)
|
||||||
|
|
||||||
# if no regular pattern was given, hence only exclude and/or intersection
|
# if no regular pattern was given, hence only exclude and/or intersection
|
||||||
|
@ -355,12 +355,10 @@ class Inventory(object):
|
||||||
self._pattern_cache = {}
|
self._pattern_cache = {}
|
||||||
|
|
||||||
def groups_for_host(self, host):
|
def groups_for_host(self, host):
|
||||||
results = []
|
if host in self._hosts_cache:
|
||||||
groups = self.get_groups()
|
return self._hosts_cache[host].get_groups()
|
||||||
for group in groups:
|
else:
|
||||||
if host in group.get_hosts():
|
return []
|
||||||
results.append(group)
|
|
||||||
return results
|
|
||||||
|
|
||||||
def groups_list(self):
|
def groups_list(self):
|
||||||
if not self._groups_list:
|
if not self._groups_list:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue