Run computed fields once for bulk delete requests

This commit is contained in:
AlanCoding
2019-03-13 15:37:01 -04:00
parent aad185e785
commit 7cf2bc2410

View File

@@ -60,7 +60,7 @@ import pytz
from wsgiref.util import FileWrapper from wsgiref.util import FileWrapper
# AWX # AWX
from awx.main.tasks import send_notifications from awx.main.tasks import send_notifications, update_inventory_computed_fields
from awx.main.access import get_user_queryset from awx.main.access import get_user_queryset
from awx.api.filters import V1CredentialFilterBackend from awx.api.filters import V1CredentialFilterBackend
from awx.api.generics import ( from awx.api.generics import (
@@ -83,6 +83,7 @@ from awx.main.utils import (
getattrd, getattrd,
get_pk_from_dict, get_pk_from_dict,
schedule_task_manager, schedule_task_manager,
ignore_inventory_computed_fields
) )
from awx.main.utils.encryption import encrypt_value from awx.main.utils.encryption import encrypt_value
from awx.main.utils.filters import SmartFilter from awx.main.utils.filters import SmartFilter
@@ -2079,12 +2080,16 @@ class InventorySourceHostsList(HostRelatedSearchMixin, SubListDestroyAPIView):
check_sub_obj_permission = False check_sub_obj_permission = False
def perform_list_destroy(self, instance_list): def perform_list_destroy(self, instance_list):
# Activity stream doesn't record disassociation here anyway inv_source = self.get_parent_object()
# no signals-related reason to not bulk-delete with ignore_inventory_computed_fields():
models.Host.groups.through.objects.filter( # Activity stream doesn't record disassociation here anyway
host__inventory_sources=self.get_parent_object() # no signals-related reason to not bulk-delete
).delete() models.Host.groups.through.objects.filter(
return super(InventorySourceHostsList, self).perform_list_destroy(instance_list) host__inventory_sources=inv_source
).delete()
r = super(InventorySourceHostsList, self).perform_list_destroy(instance_list)
update_inventory_computed_fields.delay(inv_source.inventory_id, True)
return r
class InventorySourceGroupsList(SubListDestroyAPIView): class InventorySourceGroupsList(SubListDestroyAPIView):
@@ -2096,11 +2101,15 @@ class InventorySourceGroupsList(SubListDestroyAPIView):
check_sub_obj_permission = False check_sub_obj_permission = False
def perform_list_destroy(self, instance_list): def perform_list_destroy(self, instance_list):
# Same arguments for bulk delete as with host list inv_source = self.get_parent_object()
models.Group.hosts.through.objects.filter( with ignore_inventory_computed_fields():
group__inventory_sources=self.get_parent_object() # Same arguments for bulk delete as with host list
).delete() models.Group.hosts.through.objects.filter(
return super(InventorySourceGroupsList, self).perform_list_destroy(instance_list) group__inventory_sources=inv_source
).delete()
r = super(InventorySourceGroupsList, self).perform_list_destroy(instance_list)
update_inventory_computed_fields.delay(inv_source.inventory_id, True)
return r
class InventorySourceUpdatesList(SubListAPIView): class InventorySourceUpdatesList(SubListAPIView):