From a0d35acb49b0e0b2ce5d134ddb912daf9bd5c300 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Tue, 12 Nov 2019 13:29:58 +0100 Subject: [PATCH] Add index on source_object_id for 10x performance improvment on orderBy --- .../migrations/0049_auto_20191112_1227.py | 18 ++++++++++++++++++ opentech/apply/activity/models.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 opentech/apply/activity/migrations/0049_auto_20191112_1227.py diff --git a/opentech/apply/activity/migrations/0049_auto_20191112_1227.py b/opentech/apply/activity/migrations/0049_auto_20191112_1227.py new file mode 100644 index 000000000..a79cea172 --- /dev/null +++ b/opentech/apply/activity/migrations/0049_auto_20191112_1227.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.11 on 2019-11-12 12:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('activity', '0048_add_project_transition'), + ] + + operations = [ + migrations.AlterField( + model_name='activity', + name='source_object_id', + field=models.PositiveIntegerField(blank=True, db_index=True, null=True), + ), + ] diff --git a/opentech/apply/activity/models.py b/opentech/apply/activity/models.py index 44cd95989..cf37ef0c2 100644 --- a/opentech/apply/activity/models.py +++ b/opentech/apply/activity/models.py @@ -90,7 +90,7 @@ class Activity(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT) source_content_type = models.ForeignKey(ContentType, blank=True, null=True, on_delete=models.CASCADE, related_name='activity_source') - source_object_id = models.PositiveIntegerField(blank=True, null=True) + source_object_id = models.PositiveIntegerField(blank=True, null=True, db_index=True) source = GenericForeignKey('source_content_type', 'source_object_id') message = models.TextField() -- GitLab