Optimizing groups_for_host() lookup in inventory

This commit is contained in:
James Cammarata 2014-07-07 21:08:39 -05:00
parent fe892fccb1
commit aa261bdd14

View file

@ -206,7 +206,7 @@ class Inventory(object):
pattern_exclude.append(p)
elif p.startswith("&"):
pattern_intersection.append(p)
else:
elif p:
pattern_regular.append(p)
# if no regular pattern was given, hence only exclude and/or intersection
@ -355,12 +355,10 @@ class Inventory(object):
self._pattern_cache = {}
def groups_for_host(self, host):
results = []
groups = self.get_groups()
for group in groups:
if host in group.get_hosts():
results.append(group)
return results
if host in self._hosts_cache:
return self._hosts_cache[host].get_groups()
else:
return []
def groups_list(self):
if not self._groups_list: