AC-847 Fix for inventory import performance.

This commit is contained in:
Chris Church
2013-12-18 16:35:32 -05:00
parent 24ba1c3055
commit 509b476e09
6 changed files with 932 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
# All Rights Reserved.
# Python
import contextlib
import logging
import threading
import json
@@ -24,6 +25,17 @@ logger = logging.getLogger('awx.main.signals')
_inventory_updating = threading.local()
@contextlib.contextmanager
def ignore_inventory_computed_fields():
'''
Context manager to ignore updating inventory computed fields.
'''
try:
_inventory_updating.is_updating = True
yield
finally:
_inventory_updating.is_updating = False
def update_inventory_computed_fields(sender, **kwargs):
'''
Signal handler and wrapper around inventory.update_computed_fields to
@@ -53,13 +65,10 @@ def update_inventory_computed_fields(sender, **kwargs):
return
logger.debug('%s %s, updating inventory computed fields: %r %r',
sender_name, sender_action, sender, kwargs)
try:
_inventory_updating.is_updating = True
with ignore_inventory_computed_fields():
inventory = instance.inventory
update_hosts = issubclass(sender, Job)
inventory.update_computed_fields(update_hosts=update_hosts)
finally:
_inventory_updating.is_updating = False
post_save.connect(update_inventory_computed_fields, sender=Host)
post_delete.connect(update_inventory_computed_fields, sender=Host)