From d47f367fea8dfda1e5bce918419a1bda1dd0e10b Mon Sep 17 00:00:00 2001 From: Carlos Proensa Date: Tue, 8 Nov 2016 01:30:58 +0100 Subject: [PATCH] Unify populating bug columns data cache Unify the population of data caches related to the columns that are going to be displayed. --- core/bug_api.php | 48 ++++++++++++++++++++++++++++++++++++++++++ core/columns_api.php | 20 ------------------ core/filter_api.php | 4 ---- csv_export.php | 8 +------ excel_xml_export.php | 8 +------ print_all_bug_page.php | 4 ++-- view_all_bug_page.php | 9 -------- view_all_inc.php | 12 +++-------- 8 files changed, 55 insertions(+), 58 deletions(-) diff --git a/core/bug_api.php b/core/bug_api.php index ae7b498f0a..71c28ffac6 100644 --- a/core/bug_api.php +++ b/core/bug_api.php @@ -2197,4 +2197,52 @@ function bug_clear_cache_all( $p_bug_id = null ) { file_bug_attachment_count_clear_cache( $p_bug_id ); bugnote_clear_bug_cache( $p_bug_id ); return true; +} + +/** + * Populate the caches related to the selected columns + * @param array $p_bugs Array of BugData objects + * @param array $p_selected_columns Array of columns to show + */ +function bug_cache_columns_data( array $p_bugs, array $p_selected_columns ) { + $t_bug_ids = array(); + $t_user_ids = array(); + $t_project_ids = array(); + $t_category_ids = array(); + foreach( $p_bugs as $t_bug ) { + $t_bug_ids[] = (int)$t_bug->id; + $t_user_ids[] = (int)$t_bug->handler_id; + $t_user_ids[] = (int)$t_bug->reporter_id; + $t_project_ids[] = (int)$t_bug->project_id; + $t_category_ids[] = (int)$t_bug->category_id; + } + $t_user_ids = array_unique( $t_user_ids ); + $t_project_ids = array_unique( $t_project_ids ); + $t_category_ids = array_unique( $t_category_ids ); + + foreach( $p_selected_columns as $t_column ) { + + if( column_is_plugin_column( $t_column ) ) { + $plugin_objects = columns_get_plugin_columns(); + $plugin_objects[$t_column]->cache( $p_bugs ); + continue; + } + + switch( $t_column ) { + case 'attachment_count': + file_bug_attachment_count_cache( $t_bug_ids ); + break; + case 'handler_id': + case 'reporter_id': + case 'status': + user_cache_array_rows( $t_user_ids ); + break; + case 'project_id': + project_cache_array_rows( $t_project_ids ); + break; + case 'category_id': + category_cache_array_rows( $t_category_ids ); + break; + } + } } \ No newline at end of file diff --git a/core/columns_api.php b/core/columns_api.php index 90b4917135..6843fef106 100644 --- a/core/columns_api.php +++ b/core/columns_api.php @@ -204,26 +204,6 @@ function column_is_plugin_column( $p_column ) { return isset( $t_plugin_columns[$p_column] ); } -/** - * Allow plugin columns to pre-cache data for a set of issues - * rather than requiring repeated queries for each issue. - * If the user columns parameter is provided, only plugin columns that are - * contained in that column set will be cached. - * @param array $p_bugs Array of BugData objects. - * @param array $p_selected_columns Array of columns the user is visualizing - * @return void - */ -function columns_plugin_cache_issue_data( array $p_bugs, array $p_selected_columns = null ) { - $t_columns = columns_get_plugin_columns(); - $t_all = ( null === $p_selected_columns ); - - foreach( $t_columns as $t_name => $t_column_object ) { - if( $t_all || in_array( $t_name, $p_selected_columns ) ) { - $t_column_object->cache( $p_bugs ); - } - } -} - /** * Get all accessible columns for the current project / current user. * @param integer $p_project_id A project identifier. diff --git a/core/filter_api.php b/core/filter_api.php index 5532bc1bfa..d1c3759b98 100644 --- a/core/filter_api.php +++ b/core/filter_api.php @@ -2233,17 +2233,13 @@ function filter_get_bug_rows_query_clauses( array $p_filter, $p_project_id = nul function filter_cache_result( array $p_rows, array $p_id_array_lastmod ) { $t_stats = bug_get_bugnote_stats_array( $p_id_array_lastmod ); $t_rows = array(); - $t_bug_ids = array(); foreach( $p_rows as $t_row ) { - $t_bug_ids[] = (int)$t_row['id']; if( array_key_exists( $t_row['id'], $t_stats ) ) { $t_rows[] = bug_row_to_object( bug_cache_database_result( $t_row, $t_stats[$t_row['id']] ) ); } else { $t_rows[] = bug_row_to_object( bug_cache_database_result( $t_row ) ); } } - #cache the attachment count for bug list - file_bug_attachment_count_cache( $t_bug_ids ); return $t_rows; } diff --git a/csv_export.php b/csv_export.php index b964379ca6..093b315a83 100644 --- a/csv_export.php +++ b/csv_export.php @@ -119,11 +119,6 @@ break; } $t_bug_id_array[] = (int)$t_row['id']; - $t_handler_id = (int)$t_row['handler_id']; - $t_unique_user_ids[$t_handler_id] = $t_handler_id; - $t_reporter_id = (int)$t_row['reporter_id']; - $t_unique_user_ids[$t_reporter_id] = $t_reporter_id; - $t_read_rows[] = $t_row; $t_count++; } @@ -132,8 +127,7 @@ # convert and cache data $t_rows = filter_cache_result( $t_read_rows, $t_bug_id_array ); - user_cache_array_rows( $t_unique_user_ids ); - columns_plugin_cache_issue_data( $t_rows, $t_columns ); + bug_cache_columns_data( $t_rows, $t_columns ); # Clear arrays that are not needed unset( $t_read_rows ); diff --git a/excel_xml_export.php b/excel_xml_export.php index 55ea5f6134..6114d4fc91 100644 --- a/excel_xml_export.php +++ b/excel_xml_export.php @@ -109,11 +109,6 @@ # @TODO, the "export" bug list parameter functionality should be implemented in a more efficient way if( is_blank( $f_export ) || in_array( $t_row['id'], $f_bug_arr ) ) { $t_bug_id_array[] = (int)$t_row['id']; - $t_handler_id = (int)$t_row['handler_id']; - $t_unique_user_ids[$t_handler_id] = $t_handler_id; - $t_reporter_id = (int)$t_row['reporter_id']; - $t_unique_user_ids[$t_reporter_id] = $t_reporter_id; - $t_read_rows[] = $t_row; $t_count++; } @@ -129,8 +124,7 @@ # convert and cache data $t_rows = filter_cache_result( $t_read_rows, $t_bug_id_array ); - user_cache_array_rows( $t_unique_user_ids ); - columns_plugin_cache_issue_data( $t_rows, $t_columns ); + bug_cache_columns_data( $t_rows, $t_columns ); # Clear arrays that are not needed unset( $t_read_rows ); diff --git a/print_all_bug_page.php b/print_all_bug_page.php index 9b593af045..28d381731e 100644 --- a/print_all_bug_page.php +++ b/print_all_bug_page.php @@ -99,8 +99,8 @@ $t_result = filter_get_bug_rows( $f_page_number, $t_per_page, $t_page_count, $t_bug_count ); $t_row_count = count( $t_result ); -# pre-cache custom column data -columns_plugin_cache_issue_data( $t_result, $t_columns ); +# pre-cache column data +bug_cache_columns_data( $t_result, $t_columns ); # for export $t_show_flag = gpc_get_int( 'show_flag', 0 ); diff --git a/view_all_bug_page.php b/view_all_bug_page.php index 50f0d4e966..58fbcaf1a6 100644 --- a/view_all_bug_page.php +++ b/view_all_bug_page.php @@ -79,16 +79,7 @@ $t_row_count = count( $t_rows ); for( $i=0; $i < $t_row_count; $i++ ) { array_push( $t_bugslist, $t_rows[$i]->id ); - $t_handler_id = $t_rows[$i]->handler_id; - $t_unique_user_ids[$t_handler_id] = $t_handler_id; - $t_reporter_id = $t_rows[$i]->reporter_id; - $t_unique_user_ids[$t_reporter_id] = $t_reporter_id; - $t_project_id = $t_rows[$i]->project_id; - $t_unique_project_ids[$t_project_id] = $t_project_id; } -user_cache_array_rows( $t_unique_user_ids ); -project_cache_array_rows( $t_unique_project_ids ); - gpc_set_cookie( config_get( 'bug_list_cookie' ), implode( ',', $t_bugslist ) ); compress_enable(); diff --git a/view_all_inc.php b/view_all_inc.php index 42196c5cb0..e8cfe4bcaa 100644 --- a/view_all_inc.php +++ b/view_all_inc.php @@ -66,15 +66,12 @@ # Improve performance by caching category data in one pass if( helper_get_current_project() > 0 ) { category_get_all_rows( helper_get_current_project() ); -} else { - $t_categories = array(); - foreach ( $t_rows as $t_row ) { - $t_categories[] = $t_row->category_id; - } - category_cache_array_rows( array_unique( $t_categories ) ); } + $g_columns = helper_get_columns_to_view( COLUMNS_TARGET_VIEW_PAGE ); +bug_cache_columns_data( $t_rows, $g_columns ); + $t_col_count = count( $g_columns ); $t_filter_position = config_get( 'filter_position' ); @@ -174,9 +171,6 @@ function write_bug_rows( array $p_rows ) { $t_in_stickies = ( $g_filter && ( 'on' == $g_filter[FILTER_PROPERTY_STICKY] ) ); - # pre-cache custom column data - columns_plugin_cache_issue_data( $p_rows, $g_columns ); - # -- Loop over bug rows -- $t_rows = count( $p_rows );