Actually do the right indexes in migrations

This commit is contained in:
Andrew Godwin 2023-02-03 22:24:28 -07:00
parent 36676fad59
commit f7948a55bf
9 changed files with 40 additions and 70 deletions

View file

@ -1,44 +1,19 @@
# Generated by Django 4.1.4 on 2023-02-04 01:05
# Generated by Django 4.1.4 on 2023-02-04 05:23
from django.db import migrations, models
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("users", "0013_stator_indexes"),
("activities", "0009_alter_timelineevent_index_together"),
]
operations = [
migrations.AlterField(
model_name="emoji",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="fanout",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="hashtag",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="post",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="postattachment",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="postinteraction",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
migrations.AlterIndexTogether(
name="emoji",
index_together={("state_ready", "state_locked_until", "state")},
),
migrations.AlterIndexTogether(
name="fanout",
@ -48,8 +23,19 @@ class Migration(migrations.Migration):
name="hashtag",
index_together={("state_ready", "state_locked_until", "state")},
),
migrations.AlterIndexTogether(
name="post",
index_together={("state_ready", "state_locked_until", "state")},
),
migrations.AlterIndexTogether(
name="postattachment",
index_together={("state_ready", "state_locked_until", "state")},
),
migrations.AlterIndexTogether(
name="postinteraction",
index_together={
("type", "identity", "post"),
("state_ready", "state_locked_until", "state"),
},
),
]

View file

@ -123,6 +123,7 @@ class Emoji(StatorModel):
class Meta:
unique_together = ("domain", "shortcode")
index_together = StatorModel.Meta.index_together
class urls(urlman.Urls):
admin = "/admin/emoji/"

View file

@ -319,6 +319,7 @@ class Post(StatorModel):
name="ix_post_local_public_created",
),
]
index_together = StatorModel.Meta.index_together
class urls(urlman.Urls):
view = "{self.author.urls.view}posts/{self.id}/"

View file

@ -162,7 +162,9 @@ class PostInteraction(StatorModel):
updated = models.DateTimeField(auto_now=True)
class Meta:
index_together = [["type", "identity", "post"]]
index_together = [
["type", "identity", "post"]
] + StatorModel.Meta.index_together
### Display helpers ###

View file

@ -84,7 +84,7 @@ class StatorModel(models.Model):
state: StateField
# If this row is up for transition attempts (which it always is on creation!)
state_ready = models.BooleanField(default=True, db_index=True)
state_ready = models.BooleanField(default=True)
# When the state last actually changed, or the date of instance creation
state_changed = models.DateTimeField(auto_now_add=True)
@ -102,7 +102,7 @@ class StatorModel(models.Model):
class Meta:
abstract = True
index_together = ["state_ready", "state_locked_until", "state"]
index_together = [("state_ready", "state_locked_until", "state")]
# Need this empty indexes to ensure child Models have a Meta.indexes
# that will look to add indexes (that we inject with class_prepared)
indexes: list = []

View file

@ -1,6 +1,6 @@
# Generated by Django 4.1.4 on 2023-02-04 01:05
# Generated by Django 4.1.4 on 2023-02-04 05:23
from django.db import migrations, models
from django.db import migrations
class Migration(migrations.Migration):
@ -10,45 +10,22 @@ class Migration(migrations.Migration):
]
operations = [
migrations.AlterField(
model_name="block",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="domain",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="follow",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="identity",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="inboxmessage",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="passwordreset",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
),
migrations.AlterField(
model_name="report",
name="state_ready",
field=models.BooleanField(db_index=True, default=True),
migrations.AlterIndexTogether(
name="block",
index_together={("state_ready", "state_locked_until", "state")},
),
migrations.AlterIndexTogether(
name="domain",
index_together={("state_ready", "state_locked_until", "state")},
),
migrations.AlterIndexTogether(
name="follow",
index_together={("state_ready", "state_locked_until", "state")},
),
migrations.AlterIndexTogether(
name="identity",
index_together={("state_ready", "state_locked_until", "state")},
),
migrations.AlterIndexTogether(
name="inboxmessage",
index_together={("state_ready", "state_locked_until", "state")},

View file

@ -136,6 +136,7 @@ class Block(StatorModel):
class Meta:
unique_together = [("source", "target", "mute")]
index_together = StatorModel.Meta.index_together
def __str__(self):
return f"#{self.id}: {self.source} blocks {self.target}"

View file

@ -146,6 +146,7 @@ class Follow(StatorModel):
class Meta:
unique_together = [("source", "target")]
index_together = StatorModel.Meta.index_together
def __str__(self):
return f"#{self.id}: {self.source}{self.target}"

View file

@ -227,6 +227,7 @@ class Identity(StatorModel):
class Meta:
verbose_name_plural = "identities"
unique_together = [("username", "domain")]
index_together = StatorModel.Meta.index_together
class urls(urlman.Urls):
view = "/@{self.username}@{self.domain_id}/"