From 183763e7281827b1844ec91664f78eb85fbf85b3 Mon Sep 17 00:00:00 2001 From: Carlos Proensa Date: Thu, 17 Aug 2017 15:05:32 +0200 Subject: [PATCH 1/2] Cache all needed projects for navbar layout Reduce DB query count by caching all needed projects for the navbar layout. Fixes: #23237 --- core/layout_api.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/layout_api.php b/core/layout_api.php index 03ee6acc4b..7587773c6e 100644 --- a/core/layout_api.php +++ b/core/layout_api.php @@ -615,9 +615,13 @@ function layout_navbar_button_bar() { */ function layout_navbar_projects_list( $p_project_id = null, $p_include_all_projects = true, $p_filter_project_id = null, $p_trace = false, $p_can_report_only = false ) { $t_user_id = auth_get_current_user_id(); + + # Cache all needed projects + project_cache_array_rows( user_get_all_accessible_projects( $t_user_id ) ); + + # Get top level projects $t_project_ids = user_get_accessible_projects( $t_user_id ); $t_can_report = true; - project_cache_array_rows( $t_project_ids ); if( $p_include_all_projects && $p_filter_project_id !== ALL_PROJECTS ) { echo ALL_PROJECTS == $p_project_id ? '
  • ' : '
  • '; From cce047ce0ee6f4f1963744f85ba443836715bc35 Mon Sep 17 00:00:00 2001 From: Carlos Proensa Date: Thu, 17 Aug 2017 15:33:59 +0200 Subject: [PATCH 2/2] Cache projects used in filter query The projects will be used to check access level, that will require reading the project rows from database. Making sure the projects rows are cached avoids having individual queries later for each project. --- core/filter_api.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/filter_api.php b/core/filter_api.php index c050d1953a..21aaf40848 100644 --- a/core/filter_api.php +++ b/core/filter_api.php @@ -1492,6 +1492,8 @@ function filter_get_bug_rows_query_clauses( array $p_filter, $p_project_id = nul $t_private_and_public_project_ids = array(); $t_limited_projects = array(); + # make sure the project rows are cached, as they will be used to check access levels. + project_cache_array_rows( $t_project_ids ); foreach( $t_project_ids as $t_pid ) { # limit reporters to visible projects if( ( ON === $t_limit_reporters ) && ( !access_has_project_level( access_threshold_min_level( config_get( 'report_bug_threshold', null, $t_user_id, $t_pid ) ) + 1, $t_pid, $t_user_id ) ) ) {