Add index for Grouping.grouping_key (and project)

This commit is contained in:
Klaas van Schelven
2025-05-05 22:45:33 +02:00
parent c292d9f87c
commit 392f5a30be
2 changed files with 25 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("projects", "0011_fill_stored_event_count"),
("issues", "0013_fix_issue_stored_event_counts"),
]
operations = [
migrations.AlterUniqueTogether(
name="grouping",
unique_together={("project", "grouping_key")},
),
]

View File

@@ -198,8 +198,8 @@ class Grouping(models.Model):
"projects.Project", blank=False, null=True, on_delete=models.SET_NULL) # SET_NULL: cleanup 'later'
# NOTE: I don't want to have any principled maximum on the grouping key, nor do I want to prematurely optimize the
# lookup. If lookups are slow, we _could_ examine whether manually hashing these values and matching on the hash
# helps.
# lookup. If lookups are slow (even with an index), we _could_ examine whether manually hashing these values and
# matching on the hash helps.
grouping_key = models.TextField(blank=False, null=False)
issue = models.ForeignKey("Issue", blank=False, null=True, on_delete=models.SET_NULL) # SET_NULL: cleanup 'later'
@@ -207,6 +207,13 @@ class Grouping(models.Model):
def __str__(self):
return self.grouping_key
class Meta:
unique_together = [
# principled: grouping _key_ is a _key_ for a reason (within a project). This also implies the main way of
# looking up groupings has an appropriate index.
("project", "grouping_key"),
]
def format_unmute_reason(unmute_metadata):
if "mute_until" in unmute_metadata: