mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +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:
@@ -370,7 +370,7 @@ def send_stream_creation_events_for_private_streams(
|
||||
notify_user_ids = list(stream_users_ids - realm_admin_ids)
|
||||
|
||||
if notify_user_ids:
|
||||
send_stream_creation_event(stream, notify_user_ids)
|
||||
send_stream_creation_event(realm, stream, notify_user_ids)
|
||||
|
||||
|
||||
def send_peer_subscriber_events(
|
||||
@@ -853,6 +853,8 @@ def do_change_stream_permission(
|
||||
stream.invite_only = invite_only
|
||||
stream.history_public_to_subscribers = history_public_to_subscribers
|
||||
|
||||
realm = stream.realm
|
||||
|
||||
with transaction.atomic():
|
||||
stream.save(update_fields=["invite_only", "history_public_to_subscribers", "is_web_public"])
|
||||
|
||||
@@ -871,7 +873,7 @@ def do_change_stream_permission(
|
||||
)
|
||||
|
||||
RealmAuditLog.objects.create(
|
||||
realm=stream.realm,
|
||||
realm=realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
@@ -887,7 +889,7 @@ def do_change_stream_permission(
|
||||
|
||||
if old_history_public_to_subscribers_value != stream.history_public_to_subscribers:
|
||||
RealmAuditLog.objects.create(
|
||||
realm=stream.realm,
|
||||
realm=realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
@@ -915,7 +917,7 @@ def do_change_stream_permission(
|
||||
)
|
||||
|
||||
RealmAuditLog.objects.create(
|
||||
realm=stream.realm,
|
||||
realm=realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
@@ -950,7 +952,7 @@ def do_change_stream_permission(
|
||||
)
|
||||
non_guest_user_ids = set(active_non_guest_user_ids(stream.realm_id))
|
||||
notify_stream_creation_ids = non_guest_user_ids - old_can_access_stream_user_ids
|
||||
send_stream_creation_event(stream, list(notify_stream_creation_ids))
|
||||
send_stream_creation_event(realm, stream, list(notify_stream_creation_ids))
|
||||
|
||||
# Add subscribers info to the stream object. We need to send peer_add
|
||||
# events to users who were previously subscribed to the streams as
|
||||
|
||||
@@ -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