Skip to content

Commit

Permalink
Force storing empty bugnote statistics
Browse files Browse the repository at this point in the history
(1) When a bug has no bugnotes, or visible ones, force storing a 'false'
value as bugnote stats in bug cache, to avoid querying the database again
later.

(2) Additionally, when the function bug_cache_database_result is called
with a stats array parameter, and the bug has already been cached, force
the creation of the stats index. Previously this wasn't possible if the
bug had already been cached without the bugnote stats.

Fixes #0020121
  • Loading branch information
cproensa authored and dregad committed Aug 19, 2016
1 parent 0b175c8 commit 6d6cd55
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
27 changes: 19 additions & 8 deletions core/bug_api.php
Expand Up @@ -790,16 +790,24 @@ function update( $p_update_extended = false, $p_bypass_mail = false ) {

/**
* Cache a database result-set containing full contents of bug_table row.
* @param array $p_bug_database_result Database row containing all columns from mantis_bug_table.
* @param array $p_stats An optional array representing bugnote statistics.
* $p_stats parameter is an optional array representing bugnote statistics.
* This parameter can be "false" if the bug has no bugnotes, so the cache can differentiate
* from a still not cached stats registry.
* @param array $p_bug_database_result Database row containing all columns from mantis_bug_table.
* @param array|boolean|null $p_stats Optional: array representing bugnote statistics, or false to store empty cache value
* @return array returns an array representing the bug row if bug exists
* @access public
*/
function bug_cache_database_result( array $p_bug_database_result, array $p_stats = null ) {
function bug_cache_database_result( array $p_bug_database_result, $p_stats = null ) {
global $g_cache_bug;

if( !is_array( $p_bug_database_result ) || isset( $g_cache_bug[(int)$p_bug_database_result['id']] ) ) {
return $g_cache_bug[(int)$p_bug_database_result['id']];
if( !is_null($p_stats) ) {
# force store the bugnote statistics
return bug_add_to_cache( $p_bug_database_result, $p_stats );
} else {
return $g_cache_bug[(int)$p_bug_database_result['id']];
}
}

return bug_add_to_cache( $p_bug_database_result, $p_stats );
Expand Down Expand Up @@ -873,13 +881,16 @@ function bug_cache_array_rows( array $p_bug_id_array ) {
}

/**
* Inject a bug into the bug cache
* Inject a bug into the bug cache.
* $p_stats parameter is an optional array representing bugnote statistics.
* This parameter can be "false" if the bug has no bugnotes, so the cache can differentiate
* from a still not cached stats registry.
* @param array $p_bug_row A bug row to cache.
* @param array $p_stats Bugnote stats to cache.
* @param array|boolean|null $p_stats Array of Bugnote stats to cache, false to store empty value, null to skip
* @return array
* @access private
*/
function bug_add_to_cache( array $p_bug_row, array $p_stats = null ) {
function bug_add_to_cache( array $p_bug_row, $p_stats = null ) {
global $g_cache_bug;

$g_cache_bug[(int)$p_bug_row['id']] = $p_bug_row;
Expand Down Expand Up @@ -1624,7 +1635,7 @@ function bug_get_bugnote_stats_array( array $p_bugs_id, $p_user_id = null ) {
}
while ( $t_query_row = db_fetch_array( $t_result ) );
}
# The remaining bug ids, are those without visible notes. Save false as chached value.
# The remaining bug ids, are those without visible notes. Save false as cached value
foreach( $t_id_array as $t_id ) {
$t_stats[$t_id] = false;
}
Expand Down
3 changes: 2 additions & 1 deletion core/filter_api.php
Expand Up @@ -2196,7 +2196,8 @@ 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();
foreach( $p_rows as $t_row ) {
if( isset( $t_stats[$t_row['id']] ) && false !== $t_stats[$t_row['id']] ) {
$b = $t_stats[$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 ) );
Expand Down

0 comments on commit 6d6cd55

Please sign in to comment.