move legacy UnifiedJob stdout data to a separate unmanaged model

This data often (in the case of inventory updates) represents large data
blobs (5+MB per job run).  Storing it on the polymorphic base class
table, `main_unifiedjob`, causes it to be automatically fetched on every
query (and every polymorphic join) against that table, which can result
in _very_ poor performance for awx across the board.  Django offers
`defer()`, but it's quite complicated to sprinkle this everywhere (and
easy to get wrong/introduce side effects related to our RBAC and usage
of polymorphism).

This change moves the field definition to a separate unmanaged model
(which references the same underlying `main_unifiedjob` table) and adds
a proxy for fetching the data as needed

see https://github.com/ansible/awx/issues/200
This commit is contained in:
Ryan Petrello
2017-12-12 14:41:42 -05:00
parent 2c64a2ce63
commit 202161f090
9 changed files with 108 additions and 41 deletions
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-12-12 18:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0012_non_blank_workflow'),
]
operations = [
migrations.AlterField(
model_name='unifiedjob',
name='result_stdout_text',
field=models.TextField(editable=False, null=True),
),
# Using SeparateDatabaseAndState here allows us to update the migration
# state so that Django thinks the UnifiedJob.result_stdout_text field
# is gone _without_ actually deleting the underlying column/data
migrations.SeparateDatabaseAndState(state_operations=[
migrations.RemoveField(
model_name='unifiedjob',
name='result_stdout_text',
),
]),
# On other side of the equation, this migration introduces a new model
# which is *unmanaged* (meaning, a new table is not created for it);
# instead, this sort of "virtual" model is used to maintain an ORM
# reference to the actual `main_unifiedjob.result_stdout_text` column
migrations.CreateModel(
name='UnifiedJobDeprecatedStdout',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('result_stdout_text', models.TextField(editable=False, null=True))
],
options={
'db_table': 'main_unifiedjob',
'managed': False,
},
),
]