Skip to content

Commit

Permalink
Add speed up indexes (#11614)
Browse files Browse the repository at this point in the history
* Add speed up indexes

This dramatically improves the normal queries we do on these tables.

* Make it a list like other indexes
  • Loading branch information
ericholscher authored Sep 24, 2024
1 parent b7835d4 commit 40a05c1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
21 changes: 21 additions & 0 deletions readthedocs/integrations/migrations/0014_add_index_speedup.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
1 change: 1 addition & 0 deletions readthedocs/integrations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions readthedocs/search/migrations/0006_add_index_speedup.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
3 changes: 3 additions & 0 deletions readthedocs/search/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40a05c1

Please sign in to comment.