From bd42dfe4749bc613afca2d0b13588a44f023bc33 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 12 Sep 2017 16:35:49 -0400 Subject: [PATCH] defer UnifiedJob.result_stdout_text for improved performance result_stdout_text can be _very_ large - some customers have 5MB+ per job; querying for this in list contexts results in _very_ large datasets being read from the database which is very slow. It's very uncommon to actually need this column outside of the context of job details, so defer it. see: https://github.com/ansible/ansible-tower/issues/7568 --- awx/main/access.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/awx/main/access.py b/awx/main/access.py index d73b877389..61c6a54cbe 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -105,7 +105,14 @@ def get_user_capabilities(user, instance, **kwargs): convenient for the user interface to consume and hide or show various actions in the interface. ''' - access_class = access_registry[instance.__class__] + cls = instance.__class__ + # When `.defer()` is used w/ the Django ORM, the result is a subclass of + # the original that represents e.g., + # awx.main.models.ad_hoc_commands.AdHocCommand_Deferred_result_stdout_text + # We want to do the access registry lookup keyed on the base class name. + if getattr(cls, '_deferred', False): + cls = instance.__class__.__bases__[0] + access_class = access_registry[cls] return access_class(user).get_user_capabilities(instance, **kwargs) @@ -2071,6 +2078,7 @@ class UnifiedJobAccess(BaseAccess): # 'job_template__project', # 'job_template__credential', #) + qs = qs.defer('result_stdout_text') return qs.all()