Skip to content

Commit

Permalink
Add timeline issue access check + reduce queries
Browse files Browse the repository at this point in the history
- Add access level that issues are visible now that we work directly on history rows.
- Only retrieve the N required rows for the default view, some of the N may be filtered later, causing the view to have less than N entries.
  • Loading branch information
vboctor committed Jul 6, 2015
1 parent b6a86a0 commit 25ec97f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
13 changes: 11 additions & 2 deletions core/history_api.php
Expand Up @@ -184,10 +184,15 @@ function history_count_user_recent_events( $p_duration_in_seconds, $p_user_id =
* @param integer $p_user_id A valid user identifier.
* @param integer $p_start_time The start time to filter by, or null for all.
* @param integer $p_end_time The end time to filter by, or null for all.
* @param integer $p_max_events The maximum number of events to return or null/0 for all.
* @return array
*/
function history_get_raw_events_array( $p_bug_id, $p_user_id = null, $p_start_time = null, $p_end_time = null ) {
$t_history_order = config_get( 'history_order' );
function history_get_raw_events_array( $p_bug_id, $p_user_id = null, $p_start_time = null, $p_end_time = null, $p_max_events = null, $p_sort_order = null ) {
if ( $p_sort_order === null ) {
$t_history_order = config_get( 'history_order' );
} else {
$t_history_order = $p_sort_order;
}

$t_user_id = (( null === $p_user_id ) ? auth_get_current_user_id() : $p_user_id );

Expand Down Expand Up @@ -339,6 +344,10 @@ function history_get_raw_events_array( $p_bug_id, $p_user_id = null, $p_start_ti
$t_raw_history[$j]['new_value'] = $v_new_value;

$j++;

if ( $p_max_events !== null && $p_max_events !== 0 && $j >= $p_max_events ) {
break;
}
}

# end for loop
Expand Down
3 changes: 1 addition & 2 deletions core/timeline_api.php
Expand Up @@ -42,8 +42,7 @@
function timeline_events( $p_start_time, $p_end_time, $p_max_events ) {
$t_timeline_events = array();

$t_history_events_array = history_get_raw_events_array( null, null, $p_start_time, $p_end_time );
$t_history_events_array = array_reverse( $t_history_events_array );
$t_history_events_array = history_get_raw_events_array( null, null, $p_start_time, $p_end_time, $p_max_events, 'DESC' );
$t_count = 0;

foreach ( $t_history_events_array as $t_history_event ) {
Expand Down
6 changes: 2 additions & 4 deletions core/timeline_inc.php
Expand Up @@ -46,10 +46,8 @@

timeline_print_events( $t_events );

# Don't display "More Events" link if there are no more entries to show
# Note: as of 2015-01-19, this does not cover the case of entries excluded
# by filtering (e.g. Status Change not in RESOLVED, CLOSED, REOPENED)
if( !$f_all && count( $t_events ) == $t_max_events ) {
# We will compromise accuracy of more link and showing exactly N without clicking more in favor or reducing load.
if( !$f_all ) {
echo '<p>' . $t_prev_link = ' [ <a href="my_view_page.php?days=' . $f_days . '&amp;all=1">' . lang_get( 'timeline_more' ) . '</a> ]</p>';
}

Expand Down

0 comments on commit 25ec97f

Please sign in to comment.