diff --git a/chat_box/migrations/0012_auto_20230308_1417.py b/chat_box/migrations/0012_auto_20230308_1417.py new file mode 100644 index 0000000..bd3ec5a --- /dev/null +++ b/chat_box/migrations/0012_auto_20230308_1417.py @@ -0,0 +1,34 @@ +# Generated by Django 3.2.18 on 2023-03-08 07:17 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("judge", "0154_add_submission_indexes"), + ("chat_box", "0011_alter_message_hidden"), + ] + + operations = [ + migrations.AlterModelOptions( + name="message", + options={ + "ordering": ("-id",), + "verbose_name": "message", + "verbose_name_plural": "messages", + }, + ), + migrations.AlterField( + model_name="message", + name="hidden", + field=models.BooleanField(default=False, verbose_name="is hidden"), + ), + migrations.AddIndex( + model_name="message", + index=models.Index( + fields=["hidden", "room", "-id"], name="chat_box_me_hidden_b2307a_idx" + ), + ), + ] diff --git a/chat_box/models.py b/chat_box/models.py index 2dc2cb1..61e39a6 100644 --- a/chat_box/models.py +++ b/chat_box/models.py @@ -31,7 +31,7 @@ class Message(models.Model): author = models.ForeignKey(Profile, verbose_name=_("user"), on_delete=CASCADE) time = models.DateTimeField(verbose_name=_("posted time"), auto_now_add=True) body = models.TextField(verbose_name=_("body of comment"), max_length=8192) - hidden = models.BooleanField(verbose_name="is hidden", default=False, db_index=True) + hidden = models.BooleanField(verbose_name="is hidden", default=False) room = models.ForeignKey( Room, verbose_name="room id", on_delete=CASCADE, default=None, null=True ) @@ -44,7 +44,10 @@ class Message(models.Model): class Meta: verbose_name = "message" verbose_name_plural = "messages" - ordering = ("-time",) + ordering = ("-id",) + indexes = [ + models.Index(fields=["hidden", "room", "-id"]), + ] class UserRoom(models.Model):