models: Pass args to select_related in get_stream_by_id_in_realm.

This commit updates the code to pass "realm" and "recipient" as
arguments to select_related call in get_stream_by_id_in_realm.

Previously, since there was no arguments, it fetched
can_remove_subscribers_group and the related fields of
"Realm" model as well which were not being used, but
did not fetch "recipient" as it is a nullable field.
This commit is contained in:
Sahil Batra 2023-07-21 16:41:48 +05:30 committed by Tim Abbott
parent ddee3007cb
commit ab488010b3
2 changed files with 2 additions and 2 deletions

View File

@ -2867,7 +2867,7 @@ def get_stream(stream_name: str, realm: Realm) -> Stream:
def get_stream_by_id_in_realm(stream_id: int, realm: Realm) -> Stream:
return Stream.objects.select_related().get(id=stream_id, realm=realm)
return Stream.objects.select_related("realm", "recipient").get(id=stream_id, realm=realm)
def bulk_get_streams(realm: Realm, stream_names: Set[str]) -> Dict[str, Any]:

View File

@ -3690,7 +3690,7 @@ class EditMessageTest(EditMessageTestCase):
"iago", "test move stream", "new stream", "test"
)
with self.assert_database_query_count(57), cache_tries_captured() as cache_tries:
with self.assert_database_query_count(56), cache_tries_captured() as cache_tries:
result = self.client_patch(
f"/json/messages/{msg_id}",
{