Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

create_user: Create historical UserMessage rows with bulk_create.

Anders Kaseorgfef365248b4d
diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.py
index 6e30be9e93f..2bbd08b5f6b 100644
--- a/zerver/actions/create_user.py
+++ b/zerver/actions/create_user.py
@@ -59,8 +59,10 @@ ONBOARDING_TOTAL_MESSAGES = 1000
ONBOARDING_UNREAD_MESSAGES = 20
ONBOARDING_RECENT_TIMEDELTA = datetime.timedelta(weeks=1)
+DEFAULT_HISTORICAL_FLAGS = UserMessage.flags.historical | UserMessage.flags.read
-def create_historical_user_messages(*, user_id: int, message_ids: List[int]) -> None:
+
+def create_historical_user_messages(*, user_id: int, message_ids: Iterable[int]) -> None:
# Users can see and interact with messages sent to streams with
# public history for which they do not have a UserMessage because
# they were not a subscriber at the time the message was sent.
@@ -68,12 +70,10 @@ def create_historical_user_messages(*, user_id: int, message_ids: List[int]) ->
# those messages, we create UserMessage objects for those messages;
# these have the special historical flag which keeps track of the
# fact that the user did not receive the message at the time it was sent.
- for message_id in message_ids:
- UserMessage.objects.create(
- user_profile_id=user_id,
- message_id=message_id,
- flags=UserMessage.flags.historical | UserMessage.flags.read,
- )
+ UserMessage.objects.bulk_create(
+ UserMessage(user_profile_id=user_id, message_id=message_id, flags=DEFAULT_HISTORICAL_FLAGS)
+ for message_id in message_ids
+ )
def send_message_to_signup_notification_stream(