From fef365248b4dc10f46c0e175e69597f739490c92 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 16 Nov 2022 17:43:58 -0800 Subject: [PATCH] create_user: Create historical UserMessage rows with bulk_create. Signed-off-by: Anders Kaseorg --- zerver/actions/create_user.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.py index 6e30be9e93..2bbd08b5f6 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(