From 1bb6c17fe27d0deacc3bd0a3b763903fa35725df Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 13 Sep 2017 23:00:48 -0400 Subject: [PATCH] trick django-polymorphic into allowing `defer()` on polymorphic objects django-polymorphic itself generates queries for polymorphic object lookups, and these queries for UnifiedJob are *not* properly defering the `result_stdout_text` column, resulting in more very slow queries. This solution is _very_ hacky, and very specific to this specific version of Django and django-polymorphic, but it works until we can solve this problem the proper way in 3.3 (by removing large stdout blobs from the database). see: https://github.com/ansible/ansible-tower/issues/7568 --- awx/main/models/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/awx/main/models/__init__.py b/awx/main/models/__init__.py index 01bd68cc66..c044997fca 100644 --- a/awx/main/models/__init__.py +++ b/awx/main/models/__init__.py @@ -145,3 +145,15 @@ activity_stream_registrar.connect(WorkflowJob) # prevent API filtering on certain Django-supplied sensitive fields prevent_search(User._meta.get_field('password')) + +# Always, always, always defer result_stdout_text for polymorphic UnifiedJob rows +def defer_stdout(f): + def _wrapped(*args, **kwargs): + objs = f(*args, **kwargs) + objs.query.deferred_loading[0].add('result_stdout_text') + return objs + return _wrapped + + +for cls in UnifiedJob.__subclasses__(): + cls.base_objects.filter = defer_stdout(cls.base_objects.filter)