Skip to content

Commit

Permalink
Filter summary improvements
Browse files Browse the repository at this point in the history
Merge PR #1442

Fixes #9757, #21931, #22099, #25163, #25165, #25168
  • Loading branch information
dregad committed Feb 14, 2019
2 parents bd71cb7 + e12f280 commit 943030b
Show file tree
Hide file tree
Showing 24 changed files with 1,037 additions and 583 deletions.
1 change: 1 addition & 0 deletions core/classes/DbQuery.class.php
Expand Up @@ -293,6 +293,7 @@ protected function db_execute( $p_limit = null, $p_offset = null ) {
trigger_error( ERROR_DB_QUERY_FAILED, ERROR );
$this->db_result = false;
}
$this->current_row = null;
return $this->db_result;
}

Expand Down
37 changes: 37 additions & 0 deletions core/filter_api.php
Expand Up @@ -101,6 +101,10 @@
# indexed by filter_id, contains the filter rows as read from db table
$g_cache_filter_db_rows = array();

# @global array $g_cache_filter_subquery
# indexed by a hash of the filter array, contains a prebuilt BugFilterQuery object
$g_cache_filter_subquery = array();

/**
* Initialize the filter API with the current filter.
* @param array $p_filter The filter to set as the current filter.
Expand Down Expand Up @@ -3550,6 +3554,7 @@ function filter_gpc_get( array $p_filter = null ) {
if( isset( $t_filter['_filter_id'] ) ) {
$t_filter_input['_filter_id'] = $t_filter['_filter_id'];
}
# Don't copy cached subquery '_subquery' property

return filter_ensure_valid_filter( $t_filter_input );
}
Expand Down Expand Up @@ -4001,6 +4006,9 @@ function filter_clean_runtime_properties( array $p_filter ) {
if( isset( $p_filter['_filter_id'] ) ) {
unset( $p_filter['_filter_id'] );
}
if( isset( $p_filter['_subquery'] ) ) {
unset( $p_filter['_subquery'] );
}
return $p_filter;
}

Expand All @@ -4017,9 +4025,38 @@ function filter_copy_runtime_properties( array $p_filter_to, array $p_filter_fro
if( isset( $p_filter_from['_filter_id'] ) ) {
$p_filter_to['_filter_id'] = $p_filter_from['_filter_id'];
}
# we don't copy '_subquery' property, which is a cached subquery object,
# and can be regenerated at demand

return $p_filter_to;
}

/**
* Return a cached BugFilterQuery object for the provided filter, configured and
* ready to be used as a subquery for building other queries.
* If the query is not in the cache, creates a new one and store it for later reuse.
* Note: Query objects are indexed by a hash value over the serialized contents of the
* filter array.
*
* Warning: Since the returned query is an object, it should not be modified in any way
* that changes the expected behavior from the original filter array, as any further
* reuse of this chached query will share the same instanced object.
* If such a modification is needed over the query object, a clone should be used
* instead, to avoid said side effects.
*
* @param array $p_filter Filter array
* @return BugFilterQuery A query object for the filter
*/
function filter_cache_subquery( array $p_filter ) {
global $g_cache_filter_subquery;

$t_hash = md5( json_encode( $p_filter ) );
if( !isset( $g_cache_filter_subquery[$t_hash] ) ) {
$g_cache_filter_subquery[$t_hash] = new BugFilterQuery( $p_filter, BugFilterQuery::QUERY_TYPE_IDS );
}

return $g_cache_filter_subquery[$t_hash];
}
/**
* Returns true if the user can use peristent filters, in contexts such as view_all_bug_page.
* Persistent filters are remembered across sessions, and are not desirable when the user is
Expand Down
11 changes: 8 additions & 3 deletions core/html_api.php
Expand Up @@ -856,11 +856,12 @@ function print_doc_menu( $p_page = '' ) {
}

/**
* Print the menu for the summary section
* Print the menu for the summary section.
* @param string $p_page Specifies the current page name so it's link can be disabled.
* @param array $p_filter Filter array, the one in use for summary pages.
* @return void
*/
function print_summary_menu( $p_page = '' ) {
function print_summary_menu( $p_page = '', array $p_filter = null ) {
# Plugin / Event added options
$t_event_menu_options = event_signal( 'EVENT_MENU_SUMMARY' );
$t_menu_options = array();
Expand All @@ -880,10 +881,12 @@ function print_summary_menu( $p_page = '' ) {

echo '<ul class="nav nav-tabs padding-18">' . "\n";

$t_filter_param = $p_filter ? filter_get_temporary_key_param( $p_filter ) : null;
foreach ( $t_pages as $t_page ) {
$t_active = $t_page['url'] == $p_page ? 'active' : '';
$t_link = $t_filter_param ? helper_url_combine( $t_page['url'], $t_filter_param ) : $t_page['url'];
echo '<li class="' . $t_active . '">' . "\n";
echo '<a href="'. helper_mantis_url( $t_page['url'] ) .'">' . "\n";
echo '<a href="'. helper_mantis_url( $t_link ) .'">' . "\n";
echo lang_get( $t_page['label'] );
echo '</a>' . "\n";
echo '</li>' . "\n";
Expand All @@ -895,6 +898,8 @@ function print_summary_menu( $p_page = '' ) {
}

echo '</ul>' . "\n";

summary_print_filter_info( $p_filter );
}

/**
Expand Down

0 comments on commit 943030b

Please sign in to comment.