mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
stream creation: Avoid stream.realm references.
We want to avoid Django going back to the database to get a realm object that the caller already has. It's actually currently the case that we often pre-fetch realm objects when we get stream objects using get_stream (using a call to select_related() with no arguments), but that is an expensive operation that we want to avoid going forward. This commit prepares us to just fetch slim objects.
This commit is contained in:
@@ -110,9 +110,9 @@ def render_stream_description(text: str, realm: Realm) -> str:
|
||||
return markdown_convert(text, message_realm=realm, no_previews=True).rendered_content
|
||||
|
||||
|
||||
def send_stream_creation_event(stream: Stream, user_ids: List[int]) -> None:
|
||||
def send_stream_creation_event(realm: Realm, stream: Stream, user_ids: List[int]) -> None:
|
||||
event = dict(type="stream", op="create", streams=[stream.to_dict()])
|
||||
send_event(stream.realm, event, user_ids)
|
||||
send_event(realm, event, user_ids)
|
||||
|
||||
|
||||
def create_stream_if_needed(
|
||||
@@ -172,10 +172,10 @@ def create_stream_if_needed(
|
||||
)
|
||||
if created:
|
||||
if stream.is_public():
|
||||
send_stream_creation_event(stream, active_non_guest_user_ids(stream.realm_id))
|
||||
send_stream_creation_event(realm, stream, active_non_guest_user_ids(stream.realm_id))
|
||||
else:
|
||||
realm_admin_ids = [user.id for user in stream.realm.get_admin_users_and_bots()]
|
||||
send_stream_creation_event(stream, realm_admin_ids)
|
||||
send_stream_creation_event(realm, stream, realm_admin_ids)
|
||||
|
||||
return stream, created
|
||||
|
||||
|
||||
Reference in New Issue
Block a user