Skip to content

Commit 959f81a

Browse files
authored
feat: performance tuning credentials admin (#2684)
this adds a single index to UserCredential.credential_id. You would think this would be implicitly indexed by the presence of a unique_together, but it isn't. I don't want to get overly exuberant with indices because we have a lot of costly writes during grading already, but I can see using SQL `EXPLAIN` that making this change does convert the django admin page from `using filesort` to `using index`, so theoretically this should speed it up. If it doesn't, I will try a different approach.
1 parent 5f49ac0 commit 959f81a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.17 on 2025-01-15 21:43
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("credentials", "0030_revoke_certificates_management_command"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="usercredential",
15+
name="credential_id",
16+
field=models.PositiveIntegerField(db_index=True),
17+
),
18+
]

credentials/apps/credentials/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class UserCredential(TimeStampedModel):
172172
limit_choices_to={"model__in": ("coursecertificate", "programcertificate", "credlybadgetemplate")},
173173
on_delete=models.CASCADE,
174174
)
175-
credential_id = models.PositiveIntegerField()
175+
credential_id = models.PositiveIntegerField(db_index=True)
176176
credential = GenericForeignKey("credential_content_type", "credential_id")
177177

178178
username = models.CharField(max_length=255, db_index=True)

0 commit comments

Comments
 (0)