Skip to content

Commit

Permalink
Unify populating bug columns data cache
Browse files Browse the repository at this point in the history
Unify the population of data caches related to the columns that are
going to be displayed.
  • Loading branch information
cproensa authored and dregad committed Nov 11, 2016
1 parent 2d8f4c0 commit d47f367
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 58 deletions.
48 changes: 48 additions & 0 deletions core/bug_api.php
Expand Up @@ -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;
}
}
}
20 changes: 0 additions & 20 deletions core/columns_api.php
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions core/filter_api.php
Expand Up @@ -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;
}

Expand Down
8 changes: 1 addition & 7 deletions csv_export.php
Expand Up @@ -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++;
}
Expand All @@ -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 );
Expand Down
8 changes: 1 addition & 7 deletions excel_xml_export.php
Expand Up @@ -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++;
}
Expand All @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions print_all_bug_page.php
Expand Up @@ -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 );
Expand Down
9 changes: 0 additions & 9 deletions view_all_bug_page.php
Expand Up @@ -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();
Expand Down
12 changes: 3 additions & 9 deletions view_all_inc.php
Expand Up @@ -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' );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit d47f367

Please sign in to comment.