streams: Optimize code for computing stream objects.

This commit updates code to optimize code for computing stream
objects to be sent with stream creation event and in response
for 'GET /streams/{stream_id}' endpoint by optimizing number
of queries while computing values for group permission settings.

This change does not benefit much currently as we only have one
stream group permission setting, but is important before we add
more stream permission settings.

There are a couple of places left where we can still optimize
the code and that would be done in further commits.
This commit is contained in:
Sahil Batra
2024-11-18 10:11:08 +05:30
committed by Tim Abbott
parent 2cc0f482e1
commit 7adc83d2a0
4 changed files with 28 additions and 6 deletions

View File

@@ -928,7 +928,8 @@ def stream_to_dict(
def get_web_public_streams(realm: Realm) -> list[APIStreamDict]: # nocoverage
query = get_web_public_streams_queryset(realm)
streams = query.only(*Stream.API_FIELDS)
stream_dicts = [stream_to_dict(stream) for stream in streams]
setting_groups_dict = get_group_setting_value_dict_for_streams(list(streams))
stream_dicts = [stream_to_dict(stream, None, setting_groups_dict) for stream in streams]
return stream_dicts