mirror of https://github.com/zulip/zulip.git
models: Add new UserMessage flag active_mobile_push_notification.
This flag is used to track which user/message pairs correspond to an active mobile push notification, that should potentially be cleared when the user reads the message. This flag should never appear on a message that is also marked as read; eventually we may want a cron job to check for that condition. We include a partial index on UserMessage for this flag.
This commit is contained in:
parent
c775be8ea4
commit
35cb7528f9
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."""
|
||||
|
||||
|
|
|
@ -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;'
|
||||
),
|
||||
]
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue