models: Add is_private flag to UserMessage and add index for it.

The is_private flag is intended to be set if recipient type is
'private'(1) or 'huddle'(3), otherwise i.e if it is 'stream'(2), it
should be unset.

This commit adds a database index for the is_private flag (which we'll
need to use it). That index is used to reset the flag if it was
already set. The already set flags were due to a previous removal of
is_me_message flag for which the values were not cleared out.

For now, the is_private flag is always 0 since the really hard part of
this migration is clearing the unspecified previous state; future
commits will fully implement it actually doing something.

History: Migration rewritten significantly by tabbott to ensure it
runs in only 3 minutes on chat.zulip.org.  A key detail in making that
work was to ensure that we use the new index for the queries to find
rows to update (which currently requires the `order_by` and `limit`
clauses).
This commit is contained in:
Shubham Padia
2018-06-24 20:19:18 +05:30
committed by Tim Abbott
parent 28589c5563
commit bf6dc4472b
6 changed files with 113 additions and 11 deletions

View File

@@ -88,6 +88,14 @@ def create_indexes() -> None:
where_clause='WHERE (flags & 8) != 0 OR (flags & 16) != 0',
)
# copied from 0177
create_index_if_not_exist(
index_name='zerver_usermessage_is_private_message_id',
table_name='zerver_usermessage',
column_string='user_profile_id, message_id',
where_clause='WHERE (flags & 2048) != 0',
)
class Command(ZulipBaseCommand):
help = """Create concurrent indexes for large tables."""