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.

message: Fetch streams in bulk in bulk_access_messages.

Anders Kaseorg342cba7b4dbd
diff --git a/zerver/lib/message.py b/zerver/lib/message.py
index 043432ed2ec..77dbc25e859 100644
--- a/zerver/lib/message.py
+++ b/zerver/lib/message.py
@@ -867,8 +867,17 @@ def bulk_access_messages(
)
)
- # TODO: Ideally, we'd do a similar bulk-stream-fetch if stream is
- # None, so that this function is fast with
+ if stream is None:
+ streams = {
+ stream.recipient_id: stream
+ for stream in Stream.objects.filter(
+ id__in={
+ message.recipient.type_id
+ for message in messages
+ if message.recipient.type == Recipient.STREAM
+ }
+ )
+ }
subscribed_recipient_ids = set(get_subscribed_stream_recipient_ids_for_user(user_profile))
@@ -879,7 +888,7 @@ def bulk_access_messages(
user_profile,
message,
has_user_message=has_user_message,
- stream=stream,
+ stream=streams.get(message.recipient_id) if stream is None else stream,
is_subscribed=is_subscribed,
):
filtered_messages.append(message)