mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	performance: Avoid computing page_params.streams in webapp.
The query to get "occupied" streams has been expensive in the past. I'm not sure how much any recent attempts to optimize that query have mitigated the issue, but since we clearly aren't sending this data, there is no reason to compute it.
This commit is contained in:
		@@ -89,7 +89,8 @@ def fetch_initial_state_data(
 | 
			
		||||
    user_avatar_url_field_optional: bool,
 | 
			
		||||
    realm: Realm,
 | 
			
		||||
    slim_presence: bool = False,
 | 
			
		||||
    include_subscribers: bool = True
 | 
			
		||||
    include_subscribers: bool = True,
 | 
			
		||||
    include_streams: bool = True,
 | 
			
		||||
) -> Dict[str, Any]:
 | 
			
		||||
    """When `event_types` is None, fetches the core data powering the
 | 
			
		||||
    webapp's `page_params` and `/api/v1/register` (for mobile/terminal
 | 
			
		||||
@@ -354,6 +355,10 @@ def fetch_initial_state_data(
 | 
			
		||||
        state['starred_messages'] = [] if user_profile is None else get_starred_message_ids(user_profile)
 | 
			
		||||
 | 
			
		||||
    if want('stream'):
 | 
			
		||||
        if include_streams:
 | 
			
		||||
            # The webapp doesn't use the data from here; instead,
 | 
			
		||||
            # it uses data from state["subscriptions"] and other
 | 
			
		||||
            # places.
 | 
			
		||||
            if user_profile is not None:
 | 
			
		||||
                state['streams'] = do_get_streams(user_profile)
 | 
			
		||||
            else:
 | 
			
		||||
@@ -914,6 +919,7 @@ def do_events_register(
 | 
			
		||||
    queue_lifespan_secs: int = 0,
 | 
			
		||||
    all_public_streams: bool = False,
 | 
			
		||||
    include_subscribers: bool = True,
 | 
			
		||||
    include_streams: bool = True,
 | 
			
		||||
    client_capabilities: Dict[str, bool] = {},
 | 
			
		||||
    narrow: Iterable[Sequence[str]] = [],
 | 
			
		||||
    fetch_event_types: Optional[Iterable[str]] = None
 | 
			
		||||
@@ -961,7 +967,8 @@ def do_events_register(
 | 
			
		||||
        user_avatar_url_field_optional=user_avatar_url_field_optional,
 | 
			
		||||
        realm=user_profile.realm,
 | 
			
		||||
        slim_presence=slim_presence,
 | 
			
		||||
        include_subscribers=include_subscribers
 | 
			
		||||
        include_subscribers=include_subscribers,
 | 
			
		||||
        include_streams=include_streams,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    # Apply events that came in while we were fetching initial data
 | 
			
		||||
 
 | 
			
		||||
@@ -133,6 +133,7 @@ def build_page_params_for_home_page_load(
 | 
			
		||||
        slim_presence=True,
 | 
			
		||||
        client_capabilities=client_capabilities,
 | 
			
		||||
        narrow=narrow,
 | 
			
		||||
        include_streams=False,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    furthest_read_time = get_furthest_read_time(user_profile)
 | 
			
		||||
@@ -180,10 +181,7 @@ def build_page_params_for_home_page_load(
 | 
			
		||||
        is_web_public_visitor=user_profile is None,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    undesired_register_ret_fields = [
 | 
			
		||||
        "streams",
 | 
			
		||||
    ]
 | 
			
		||||
    for field_name in set(register_ret.keys()) - set(undesired_register_ret_fields):
 | 
			
		||||
    for field_name in register_ret.keys():
 | 
			
		||||
        page_params[field_name] = register_ret[field_name]
 | 
			
		||||
 | 
			
		||||
    if narrow_stream is not None:
 | 
			
		||||
 
 | 
			
		||||
@@ -255,7 +255,7 @@ class HomeTest(ZulipTestCase):
 | 
			
		||||
        self.assertEqual(set(result["Cache-Control"].split(", ")),
 | 
			
		||||
                         {"must-revalidate", "no-store", "no-cache"})
 | 
			
		||||
 | 
			
		||||
        self.assert_length(queries, 42)
 | 
			
		||||
        self.assert_length(queries, 40)
 | 
			
		||||
        self.assert_length(cache_mock.call_args_list, 5)
 | 
			
		||||
 | 
			
		||||
        html = result.content.decode('utf-8')
 | 
			
		||||
@@ -321,7 +321,7 @@ class HomeTest(ZulipTestCase):
 | 
			
		||||
                result = self._get_home_page()
 | 
			
		||||
                self.check_rendered_logged_in_app(result)
 | 
			
		||||
                self.assert_length(cache_mock.call_args_list, 6)
 | 
			
		||||
            self.assert_length(queries, 39)
 | 
			
		||||
            self.assert_length(queries, 37)
 | 
			
		||||
 | 
			
		||||
    def test_num_queries_with_streams(self) -> None:
 | 
			
		||||
        main_user = self.example_user('hamlet')
 | 
			
		||||
@@ -352,7 +352,7 @@ class HomeTest(ZulipTestCase):
 | 
			
		||||
        with queries_captured() as queries2:
 | 
			
		||||
            result = self._get_home_page()
 | 
			
		||||
 | 
			
		||||
        self.assert_length(queries2, 37)
 | 
			
		||||
        self.assert_length(queries2, 35)
 | 
			
		||||
 | 
			
		||||
        # Do a sanity check that our new streams were in the payload.
 | 
			
		||||
        html = result.content.decode('utf-8')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user