From 7160bff363fb4840b93f1bee444ac3682e1a2305 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 23 May 2014 15:56:09 -0400 Subject: [PATCH] Use through table reference to slightly improve host-group association removal --- awx/main/models/inventory.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index f37c946593..fc3863a779 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -534,13 +534,8 @@ class Group(CommonModelNameNotUnique): from awx.main.tasks import update_inventory_computed_fields, bulk_inventory_element_delete from awx.main.utils import ignore_inventory_computed_fields from awx.main.signals import disable_activity_stream - # group_data = {'parent': self.id, 'inventory': self.inventory.id, - # 'children': [{'id': c.id} for c in self.children.all()], - # 'hosts': [{'id': h.id} for h in self.hosts.all()]} - #self.mark_inactive(clear_children=False) def remove_host_from_group(host, group): - #host.groups.remove(group) - host.inventory_sources.through.objects.filter(inventorysource__group=group).delete() + #host.inventory_sources.through.objects.filter(inventorysource__group=group).delete() return host.groups.count() < 2 def mark_actual(): initial_hosts = self.hosts.all().prefetch_related('groups', 'inventory_sources') @@ -553,9 +548,9 @@ class Group(CommonModelNameNotUnique): marked_hosts.append(host) self.hosts.through.objects.filter(group=self).delete() self.children.through.objects.filter(to_group=self).delete() + self.inventory_sources.through.objects.filter(group=self).delete() for subgroup in linked_children: parent, group = subgroup - #group.parents.remove(parent) if group.parents.count() > 1: continue all_group_hosts = group.hosts.all() @@ -568,6 +563,7 @@ class Group(CommonModelNameNotUnique): linked_children.append((group, childgroup)) marked_groups.append(group) group.children.through.objects.filter(to_group=group).delete() + group.inventory_sources.through.objects.filter(group=group).delete() all_groups = [g.id for g in marked_groups] all_hosts = [h.id for h in marked_hosts] Group.objects.filter(id__in=all_groups).update(active=False)