create_user: Create historical UserMessage rows with bulk_create.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2022-11-16 17:43:58 -08:00
committed by Tim Abbott
parent ee2cb855f0
commit fef365248b

View File

@@ -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(