Skip to content

Commit

Permalink
Limit processing to events that will be displayed
Browse files Browse the repository at this point in the history
Remove need to process events that will not be displayed and remove sorting.
  • Loading branch information
vboctor committed Jul 6, 2015
1 parent 8c9114e commit 2afb863
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 77 deletions.
2 changes: 1 addition & 1 deletion core/classes/IssueAssignedTimelineEvent.class.php
Expand Up @@ -38,7 +38,7 @@ class IssueAssignedTimelineEvent extends TimelineEvent {
* @param integer $p_handler_id An user identifier.
*/
public function __construct( $p_timestamp, $p_user_id, $p_issue_id, $p_handler_id ) {
parent::__construct( $p_timestamp, $p_user_id, $p_issue_id );
parent::__construct( $p_timestamp, $p_user_id );

$this->issue_id = $p_issue_id;
$this->handler_id = $p_handler_id;
Expand Down
2 changes: 1 addition & 1 deletion core/classes/IssueCreatedTimelineEvent.class.php
Expand Up @@ -36,7 +36,7 @@ class IssueCreatedTimelineEvent extends TimelineEvent {
* @param integer $p_issue_id A issue identifier.
*/
public function __construct( $p_timestamp, $p_user_id, $p_issue_id ) {
parent::__construct( $p_timestamp, $p_user_id, $p_issue_id );
parent::__construct( $p_timestamp, $p_user_id );

$this->issue_id = $p_issue_id;
}
Expand Down
2 changes: 1 addition & 1 deletion core/classes/IssueMonitorTimelineEvent.class.php
Expand Up @@ -38,7 +38,7 @@ class IssueMonitorTimelineEvent extends TimelineEvent {
* @param boolean $p_monitor Whether issue was being monitored or unmonitored.
*/
public function __construct( $p_timestamp, $p_user_id, $p_issue_id, $p_monitor ) {
parent::__construct( $p_timestamp, $p_user_id, $p_issue_id );
parent::__construct( $p_timestamp, $p_user_id );

$this->issue_id = $p_issue_id;
$this->monitor = $p_monitor;
Expand Down
2 changes: 1 addition & 1 deletion core/classes/IssueNoteCreatedTimelineEvent.class.php
Expand Up @@ -38,7 +38,7 @@ class IssueNoteCreatedTimelineEvent extends TimelineEvent {
* @param integer $p_issue_note_id A issue note identifier.
*/
public function __construct( $p_timestamp, $p_user_id, $p_issue_id, $p_issue_note_id ) {
parent::__construct( $p_timestamp, $p_user_id, $p_issue_id );
parent::__construct( $p_timestamp, $p_user_id );

$this->issue_id = $p_issue_id;
$this->issue_note_id = $p_issue_note_id;
Expand Down
2 changes: 1 addition & 1 deletion core/classes/IssueStatusChangeTimelineEvent.class.php
Expand Up @@ -50,7 +50,7 @@ class IssueStatusChangeTimelineEvent extends TimelineEvent {
* @param integer $p_new_status New status value of issue.
*/
public function __construct( $p_timestamp, $p_user_id, $p_issue_id, $p_old_status, $p_new_status ) {
parent::__construct( $p_timestamp, $p_user_id, $p_issue_id );
parent::__construct( $p_timestamp, $p_user_id );

$this->issue_id = $p_issue_id;
$this->old_status = $p_old_status;
Expand Down
2 changes: 1 addition & 1 deletion core/classes/IssueTagTimelineEvent.class.php
Expand Up @@ -40,7 +40,7 @@ class IssueTagTimelineEvent extends TimelineEvent {
* @param boolean $p_tag Whether tag was being linked or unlinked from the issue.
*/
public function __construct( $p_timestamp, $p_user_id, $p_issue_id, $p_tag_name, $p_tag ) {
parent::__construct( $p_timestamp, $p_user_id, $p_issue_id );
parent::__construct( $p_timestamp, $p_user_id );

$this->issue_id = $p_issue_id;
$this->tag_name = $p_tag_name;
Expand Down
31 changes: 1 addition & 30 deletions core/classes/TimelineEvent.class.php
Expand Up @@ -30,43 +30,14 @@
class TimelineEvent {
protected $timestamp;
protected $user_id;
protected $tie_breaker;

/**
* @param integer $p_timestamp Timestamp representing the time the event occurred.
* @param integer $p_user_id An user identifier.
* @param boolean $p_tie_breaker A value to sort events by if timestamp matches (generally issue identifier).
*/
public function __construct( $p_timestamp, $p_user_id, $p_tie_breaker ) {
public function __construct( $p_timestamp, $p_user_id ) {
$this->timestamp = $p_timestamp;
$this->user_id = $p_user_id;
$this->tie_breaker = $p_tie_breaker;
}

/**
* Comparision function for ordering of timeline events.
* We compare first by timestamp, then by the tie_breaker field.
* @param TimelineEvent $p_other An instance of TimelineEvent to compare against.
* @return integer
*/
public function compare( TimelineEvent $p_other ) {
if( $this->timestamp < $p_other->timestamp ) {
return -1;
}

if( $this->timestamp > $p_other->timestamp ) {
return 1;
}

if( $this->tie_breaker < $p_other->tie_breaker ) {
return -1;
}

if( $this->tie_breaker > $p_other->tie_breaker ) {
return 1;
}

return 0;
}

/**
Expand Down
44 changes: 9 additions & 35 deletions core/timeline_api.php
Expand Up @@ -36,13 +36,15 @@
* Events for which the skip() method returns true will be excluded
* @param integer $p_start_time Timestamp representing start time of the period.
* @param integer $p_end_time Timestamp representing end time of the period.
* @param integer $p_max_events The maximum number of events to return or 0 for unlimited.
* @return array
*/
function timeline_events( $p_start_time, $p_end_time ) {
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_count = 0;

foreach ( $t_history_events_array as $t_history_event ) {
$t_event = null;
Expand Down Expand Up @@ -89,57 +91,29 @@ function timeline_events( $p_start_time, $p_end_time ) {
# Do not include skipped events
if( $t_event != null && !$t_event->skip() ) {
$t_timeline_events[] = $t_event;
}
}
$t_count++;

return $t_timeline_events;
}

/**
* Sort an array of timeline events
* @param array $p_events Array of events being sorted.
* @return array Sorted array of events.
*/
function timeline_sort_events( array $p_events ) {
$t_count = count( $p_events );
$t_stable = false;

while( !$t_stable ) {
$t_stable = true;

for( $i = 0; $i < $t_count - 1; ++$i ) {
if( $p_events[$i]->compare( $p_events[$i+1] ) < 0 ) {
$t_temp = $p_events[$i];
$p_events[$i] = $p_events[$i+1];
$p_events[$i+1] = $t_temp;
$t_stable = false;
if ( $p_max_events > 0 && $t_count >= $p_max_events ) {
break;
}
}
}
}

return $p_events;
return $t_timeline_events;
}

/**
* Print for display an array of events
* @param array $p_events Array of events to display
* @param int $p_max_num Maximum number of events to display, 0 = all
* @return int Number of displayed events
*/
function timeline_print_events( array $p_events, $p_max_num = 0 ) {
function timeline_print_events( array $p_events ) {
if( empty( $p_events ) ) {
echo '<p>' . lang_get( 'timeline_no_activity' ) . '</p>';
return 0;
}

$i = 0;
foreach( $p_events as $t_event ) {
# Stop displaying events if we're reached the maximum
if( $p_max_num && $i++ >= $p_max_num ) {
break;
}
echo $t_event->html();
}
return min( $p_max_num, $i);
}

10 changes: 4 additions & 6 deletions core/timeline_inc.php
Expand Up @@ -17,14 +17,13 @@
require_once( 'core.php' );
require_api( 'timeline_api.php' );

define( 'MAX_EVENTS', 50 );

$f_days = gpc_get_int( 'days', 0 );
$f_all = gpc_get_int( 'all', 0 );
$t_max_events = $f_all ? 0 : 50;

$t_end_time = time() - ( $f_days * SECONDS_PER_DAY );
$t_start_time = $t_end_time - ( 7 * SECONDS_PER_DAY );
$t_events = timeline_events( $t_start_time, $t_end_time );
$t_events = timeline_events( $t_start_time, $t_end_time, $t_max_events );

echo '<div class="timeline">';

Expand All @@ -44,14 +43,13 @@
}

echo '<div class="date-range">' . date( $t_short_date_format, $t_start_time ) . ' .. ' . date( $t_short_date_format, $t_end_time ) . $t_prev_link . $t_next_link . '</div>';
$t_events = timeline_sort_events( $t_events );

$t_num_events = timeline_print_events( $t_events, ( $f_all ? 0 : MAX_EVENTS ) );
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 && $t_num_events < count( $t_events )) {
if( !$f_all && count( $t_events ) == $t_max_events ) {
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 2afb863

Please sign in to comment.