Add indexes on fields on which we order and vice versa

Triggered by issue_event_list being more than 5s on "emu" (my 1,500,000 event
test-machine). Reason: sorting those events on non-indexed field. Switching
to a field-with-index solved it.

I then analysed (grepped) for "ordering" and "order_by" and set indexes
accordingly and more or less indiscriminately (i.e. even on tables that are
assumed to have relatively few rows, such as Project & Team).
This commit is contained in:
Klaas van Schelven
2025-02-04 21:19:24 +01:00
parent 24e204edcc
commit 86e8c4318b
9 changed files with 95 additions and 4 deletions

View File

@@ -0,0 +1,19 @@
# Generated by Django 4.2.18 on 2025-02-04 20:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("snappea", "0003_task_created_at"),
]
operations = [
migrations.AddIndex(
model_name="task",
index=models.Index(
fields=["created_at"], name="snappea_tas_created_eb0824_idx"
),
),
]

View File

@@ -15,6 +15,11 @@ class Task(models.Model):
def __str__(self):
return self.task_name
class Meta:
indexes = [
models.Index(fields=['created_at']),
]
def wakeup_server():
wakeup_file = os.path.join(get_settings().WAKEUP_CALLS_DIR, thread_uuid)