From 40a05c1b22b0979bb9848459c09073c4bec4c811 Mon Sep 17 00:00:00 2001 From: Eric Holscher <25510+ericholscher@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:48:49 -0800 Subject: [PATCH] Add speed up indexes (#11614) * Add speed up indexes This dramatically improves the normal queries we do on these tables. * Make it a list like other indexes --- .../migrations/0014_add_index_speedup.py | 21 +++++++++++++++++++ readthedocs/integrations/models.py | 1 + .../migrations/0006_add_index_speedup.py | 21 +++++++++++++++++++ readthedocs/search/models.py | 3 +++ 4 files changed, 46 insertions(+) create mode 100644 readthedocs/integrations/migrations/0014_add_index_speedup.py create mode 100644 readthedocs/search/migrations/0006_add_index_speedup.py diff --git a/readthedocs/integrations/migrations/0014_add_index_speedup.py b/readthedocs/integrations/migrations/0014_add_index_speedup.py new file mode 100644 index 00000000000..168770cf3e6 --- /dev/null +++ b/readthedocs/integrations/migrations/0014_add_index_speedup.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.16 on 2024-09-23 20:22 + +from django.db import migrations, models +from django_safemigrate import Safe + + +class Migration(migrations.Migration): + safe = Safe.always + dependencies = [ + ("integrations", "0013_set_timestamp_fields_as_no_null"), + ] + + operations = [ + migrations.AddIndex( + model_name="httpexchange", + index=models.Index( + fields=["content_type", "object_id", "date"], + name="integration_content_5d4e98_idx", + ), + ), + ] diff --git a/readthedocs/integrations/models.py b/readthedocs/integrations/models.py index f360760d9df..a475eb99273 100644 --- a/readthedocs/integrations/models.py +++ b/readthedocs/integrations/models.py @@ -169,6 +169,7 @@ class HttpExchange(models.Model): class Meta: ordering = ["-date"] + indexes = [models.Index(fields=["content_type", "object_id", "date"])] def __str__(self): return _("Exchange {0}").format(self.pk) diff --git a/readthedocs/search/migrations/0006_add_index_speedup.py b/readthedocs/search/migrations/0006_add_index_speedup.py new file mode 100644 index 00000000000..6c79ecd33c3 --- /dev/null +++ b/readthedocs/search/migrations/0006_add_index_speedup.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.16 on 2024-09-23 20:22 + +from django.db import migrations, models +from django_safemigrate import Safe + + +class Migration(migrations.Migration): + safe = Safe.always + dependencies = [ + ("search", "0005_alter_searchquery_id"), + ] + + operations = [ + migrations.AddIndex( + model_name="searchquery", + index=models.Index( + fields=["modified", "project", "version"], + name="search_sear_modifie_3ac4ab_idx", + ), + ), + ] diff --git a/readthedocs/search/models.py b/readthedocs/search/models.py index 39ea10c8277..1acbf77b6e5 100644 --- a/readthedocs/search/models.py +++ b/readthedocs/search/models.py @@ -41,6 +41,9 @@ class SearchQuery(TimeStampedModel): class Meta: verbose_name = "Search query" verbose_name_plural = "Search queries" + indexes = [ + models.Index(fields=["modified", "project", "version"]), + ] def __str__(self): return self.query