mirror of
https://github.com/ansible/awx.git
synced 2026-05-22 16:27:42 -02:30
AC-847 Fix for inventory import performance.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user