mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	streams: Refactor get_web_public_streams_queryset.
This commit updates code to not prefetch group setting fields using select_related as we do not need to prefetch these settings for all the cases and we instead prefetch these in callers whenever needed.
This commit is contained in:
		@@ -880,7 +880,7 @@ def get_web_public_streams_queryset(realm: Realm) -> QuerySet[Stream]:
 | 
				
			|||||||
        # these in the query.
 | 
					        # these in the query.
 | 
				
			||||||
        invite_only=False,
 | 
					        invite_only=False,
 | 
				
			||||||
        history_public_to_subscribers=True,
 | 
					        history_public_to_subscribers=True,
 | 
				
			||||||
    ).select_related("can_send_message_group", "can_send_message_group__named_user_group")
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def check_stream_name_available(realm: Realm, name: str) -> None:
 | 
					def check_stream_name_available(realm: Realm, name: str) -> None:
 | 
				
			||||||
@@ -1530,7 +1530,13 @@ def stream_to_dict(
 | 
				
			|||||||
def get_web_public_streams(
 | 
					def get_web_public_streams(
 | 
				
			||||||
    realm: Realm, anonymous_group_membership: dict[int, UserGroupMembersData]
 | 
					    realm: Realm, anonymous_group_membership: dict[int, UserGroupMembersData]
 | 
				
			||||||
) -> list[APIStreamDict]:  # nocoverage
 | 
					) -> list[APIStreamDict]:  # nocoverage
 | 
				
			||||||
    query = get_web_public_streams_queryset(realm)
 | 
					    query = get_web_public_streams_queryset(realm).select_related(
 | 
				
			||||||
 | 
					        # TODO: We need these fields to compute stream_post_policy; we
 | 
				
			||||||
 | 
					        # can drop this select_related clause once that legacy field
 | 
				
			||||||
 | 
					        # is removed from the API.
 | 
				
			||||||
 | 
					        "can_send_message_group",
 | 
				
			||||||
 | 
					        "can_send_message_group__named_user_group",
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
    streams = query.only(*Stream.API_FIELDS)
 | 
					    streams = query.only(*Stream.API_FIELDS)
 | 
				
			||||||
    stream_dicts = [stream_to_dict(stream, None, anonymous_group_membership) for stream in streams]
 | 
					    stream_dicts = [stream_to_dict(stream, None, anonymous_group_membership) for stream in streams]
 | 
				
			||||||
    return stream_dicts
 | 
					    return stream_dicts
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,7 +57,9 @@ def get_web_public_subs(
 | 
				
			|||||||
        return color
 | 
					        return color
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    subscribed = []
 | 
					    subscribed = []
 | 
				
			||||||
    streams = get_web_public_streams_queryset(realm)
 | 
					    streams = get_web_public_streams_queryset(realm).select_related(
 | 
				
			||||||
 | 
					        "can_send_message_group", "can_send_message_group__named_user_group"
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for stream in streams:
 | 
					    for stream in streams:
 | 
				
			||||||
        # Add Stream fields.
 | 
					        # Add Stream fields.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user