fetch_initial_state: Avoid doing one db query per announcement stream.

In 'fetch_initial_state_data' we were doing one database query
per announcement stream.

This commit updates the logic to prefetch those streams using
select_related hence avoiding the extra db queries.

Fixes #28909.
This commit is contained in:
Prakhar Pratyush
2024-07-22 15:17:08 +05:30
committed by Tim Abbott
parent 3ac14632d8
commit f48e87cd3c
4 changed files with 15 additions and 7 deletions

View File

@@ -1174,7 +1174,7 @@ class FetchQueriesTest(ZulipTestCase):
realm = get_realm_with_settings(realm_id=user.realm_id)
with (
self.assert_database_query_count(43),
self.assert_database_query_count(41),
mock.patch("zerver.lib.events.always_want") as want_mock,
):
fetch_initial_state_data(user, realm=realm)
@@ -1190,7 +1190,7 @@ class FetchQueriesTest(ZulipTestCase):
muted_users=1,
onboarding_steps=1,
presence=1,
realm=3,
realm=1,
realm_bot=1,
realm_domains=1,
realm_embedded_bots=0,