diff --git a/issues/migrations/0014_alter_grouping_unique_together.py b/issues/migrations/0014_alter_grouping_unique_together.py new file mode 100644 index 0000000..9ffcbbe --- /dev/null +++ b/issues/migrations/0014_alter_grouping_unique_together.py @@ -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")}, + ), + ] diff --git a/issues/models.py b/issues/models.py index 69a320c..ac8daba 100644 --- a/issues/models.py +++ b/issues/models.py @@ -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: