diff --git a/docs/production/expensive-migrations.md b/docs/production/expensive-migrations.md index 0b2a164221..9d232eafe2 100644 --- a/docs/production/expensive-migrations.md +++ b/docs/production/expensive-migrations.md @@ -24,8 +24,12 @@ can run them manually before starting the upgrade: ON zerver_usermessage (user_profile_id, message_id) WHERE (flags & 2048) != 0; -(This first migration, `zerver_usermessage_is_private_message_id`, is -the only one new in Zulip 1.9). + CREATE INDEX CONCURRENTLY + zerver_usermessage_active_mobile_push_notification_id + ON zerver_usermessage (user_profile_id, message_id) + WHERE (flags & 4096) != 0; + +(These first migrations are the only new ones in Zulip 1.9). CREATE INDEX CONCURRENTLY zerver_usermessage_mentioned_message_id diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2 index f806089be0..16f7b315be 100755 --- a/scripts/lib/upgrade-zulip-stage-2 +++ b/scripts/lib/upgrade-zulip-stage-2 @@ -99,6 +99,7 @@ usermessage_index_migrations = [ "[ ] 0098_index_has_alert_word_user_messages", "[ ] 0099_index_wildcard_mentioned_user_messages", "[ ] 0177_user_message_add_and_index_is_private_flag", + "[ ] 0180_usermessage_add_active_mobile_push_notification", ] # Our next optimization is to check whether any migrations are needed # before we start the critical section of the restart. This saves diff --git a/zerver/management/commands/create_large_indexes.py b/zerver/management/commands/create_large_indexes.py index a166c9719a..1436cd0e31 100644 --- a/zerver/management/commands/create_large_indexes.py +++ b/zerver/management/commands/create_large_indexes.py @@ -96,6 +96,14 @@ def create_indexes() -> None: where_clause='WHERE (flags & 2048) != 0', ) + # copied from 0180 + create_index_if_not_exist( + index_name='zerver_usermessage_active_mobile_push_notification_id', + table_name='zerver_usermessage', + column_string='user_profile_id, message_id', + where_clause='WHERE (flags & 4096) != 0', + ) + class Command(ZulipBaseCommand): help = """Create concurrent indexes for large tables.""" diff --git a/zerver/migrations/0180_usermessage_add_active_mobile_push_notification.py b/zerver/migrations/0180_usermessage_add_active_mobile_push_notification.py new file mode 100644 index 0000000000..3220753d86 --- /dev/null +++ b/zerver/migrations/0180_usermessage_add_active_mobile_push_notification.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.14 on 2018-08-01 23:05 +from __future__ import unicode_literals + +import bitfield.models +from django.db import migrations +from zerver.lib.migrate import create_index_if_not_exist # nolint + + +class Migration(migrations.Migration): + + dependencies = [ + ('zerver', '0179_rename_to_digest_emails_enabled'), + ] + + operations = [ + migrations.AlterField( + model_name='archivedusermessage', + name='flags', + field=bitfield.models.BitField(['read', 'starred', 'collapsed', 'mentioned', 'wildcard_mentioned', 'summarize_in_home', 'summarize_in_stream', 'force_expand', 'force_collapse', 'has_alert_word', 'historical', 'is_private', 'active_mobile_push_notification'], default=0), + ), + migrations.AlterField( + model_name='usermessage', + name='flags', + field=bitfield.models.BitField(['read', 'starred', 'collapsed', 'mentioned', 'wildcard_mentioned', 'summarize_in_home', 'summarize_in_stream', 'force_expand', 'force_collapse', 'has_alert_word', 'historical', 'is_private', 'active_mobile_push_notification'], default=0), + ), + migrations.RunSQL( + create_index_if_not_exist( + index_name='zerver_usermessage_active_mobile_push_notification_id', + table_name='zerver_usermessage', + column_string='user_profile_id, message_id', + where_clause='WHERE (flags & 4096) != 0', + ), + reverse_sql='DROP INDEX zerver_usermessage_active_mobile_push_notification_id;' + ), + ] diff --git a/zerver/models.py b/zerver/models.py index 61d726bd4a..0b425888da 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -1524,7 +1524,7 @@ class AbstractUserMessage(models.Model): user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE) # type: UserProfile ALL_FLAGS = ['read', 'starred', 'collapsed', 'mentioned', 'wildcard_mentioned', 'summarize_in_home', 'summarize_in_stream', 'force_expand', 'force_collapse', - 'has_alert_word', "historical", "is_private"] + 'has_alert_word', "historical", "is_private", "active_mobile_push_notification"] flags = BitField(flags=ALL_FLAGS, default=0) # type: BitHandler class Meta: