From 5874c6542fb28e528b947a0042e06044b0d151ec Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Fri, 1 Sep 2023 00:45:39 +0000 Subject: [PATCH] migrations: Remove indexes on Message without realm_id. These indexes should no longer be necessary after the changes in the previous commit. --- ...473_remove_message_non_realm_id_indexes.py | 29 +++++++++++++++++++ zerver/models.py | 21 -------------- 2 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 zerver/migrations/0473_remove_message_non_realm_id_indexes.py diff --git a/zerver/migrations/0473_remove_message_non_realm_id_indexes.py b/zerver/migrations/0473_remove_message_non_realm_id_indexes.py new file mode 100644 index 0000000000..cc969468b8 --- /dev/null +++ b/zerver/migrations/0473_remove_message_non_realm_id_indexes.py @@ -0,0 +1,29 @@ +from django.contrib.postgres.operations import RemoveIndexConcurrently +from django.db import migrations + + +class Migration(migrations.Migration): + atomic = False + + dependencies = [ + ("zerver", "0472_add_message_realm_id_indexes"), + ] + + operations = [ + RemoveIndexConcurrently( + model_name="message", + name="upper_subject_idx", + ), + RemoveIndexConcurrently( + model_name="message", + name="zerver_message_recipient_upper_subject", + ), + RemoveIndexConcurrently( + model_name="message", + name="zerver_message_recipient_subject", + ), + RemoveIndexConcurrently( + model_name="scheduledmessage", + name="zerver_unsent_scheduled_messages_by_user", + ), + ] diff --git a/zerver/models.py b/zerver/models.py index 27a15d4c43..1a55cb2afd 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -3103,20 +3103,6 @@ class Message(AbstractMessage): class Meta: indexes = [ GinIndex("search_tsvector", fastupdate=False, name="zerver_message_search_tsvector"), - models.Index(Upper("subject"), name="upper_subject_idx"), - models.Index( - "recipient", - Upper("subject"), - F("id").desc(nulls_last=True), - name="zerver_message_recipient_upper_subject", - ), - models.Index( - "recipient", - "subject", - F("id").desc(nulls_last=True), - name="zerver_message_recipient_subject", - ), - # Indexes prefixed with realm_id models.Index( # For moving messages between streams or marking # streams as read. The "id" at the end makes it easy @@ -4475,13 +4461,6 @@ class ScheduledMessage(models.Model): # user themself via the API; we don't filter failed # messages since we will want to display those so that # failures don't just disappear into a black hole. - models.Index( - name="zerver_unsent_scheduled_messages_by_user", - fields=["sender", "delivery_type", "scheduled_timestamp"], - condition=Q( - delivered=False, - ), - ), models.Index( name="zerver_realm_unsent_scheduled_messages_by_user", fields=["realm_id", "sender", "delivery_type", "scheduled_timestamp"],