Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove unnecessary use of array_reverse() to display bug revisions

Prior to this commit, in bug_revision_view_page.php the array returned
by functions bug_revision_list() and bug_revision_like() was
sytematically reversed by calling array_reverse().

Since these 2 functions are not used anywhere else, it is more efficient
to modify the SQL so that the functions sort the list as it should be
right from the start, thus avoiding the calls to array_reverse().

Note that the ORDER BY clause has been changed from 'timestamp' to 'id',
this guarantees correct display order in case the timestamps are equal
since by definition the id is a sequential number increased with each
revision as it is recorded.

Fixes #14273
  • Loading branch information...
commit c08e6531eb3130d0fa83ff57d7330bfb62aa9e91 1 parent 8092900
@dregad dregad authored
Showing with 7 additions and 7 deletions.
  1. +2 −3 bug_revision_view_page.php
  2. +5 −4 core/bug_revision_api.php
View
5 bug_revision_view_page.php
@@ -41,12 +41,12 @@
$t_bug_id = bugnote_get_field( $f_bugnote_id, 'bug_id' );
$t_bug_data = bug_get( $t_bug_id, true );
- $t_bug_revisions = array_reverse( bug_revision_list( $t_bug_id, REV_ANY, $f_bugnote_id ), true );
+ $t_bug_revisions = bug_revision_list( $t_bug_id, REV_ANY, $f_bugnote_id );
$t_title = lang_get( 'bugnote' ) . ' ' . $f_bugnote_id;
} else if ( $f_rev_id ) {
- $t_bug_revisions = array_reverse( bug_revision_like( $f_rev_id ), true );
+ $t_bug_revisions = bug_revision_like( $f_rev_id );
if ( count( $t_bug_revisions ) < 1 ) {
trigger_error( ERROR_GENERIC, ERROR );
@@ -65,7 +65,6 @@ function show_revision( $t_revision ) {
static $s_can_drop = null;
static $s_drop_token = null;
static $s_user_access = null;
-
if ( is_null( $s_can_drop ) ) {
$s_can_drop = access_has_bug_level( config_get( 'bug_revision_drop_threshold' ), $t_revision['bug_id'] );
$s_drop_token = form_security_param( 'bug_revision_drop' );
View
9 core/bug_revision_api.php
@@ -268,7 +268,8 @@ function bug_revision_last( $p_bug_id, $p_type=REV_ANY, $p_bugnote_id=0 ) {
}
/**
- * Retrieve a full list of changes to the bug's information.
+ * Retrieve a full list of changes to the bug's information, sorted in
+ * reverse chronological order.
* @param int $p_bug_id Bug ID
* @param int $p_type Revision Type
* @param int $p_bugnote_id Bugnote ID
@@ -293,7 +294,7 @@ function bug_revision_list( $p_bug_id, $p_type=REV_ANY, $p_bugnote_id=0 ) {
$t_query .= ' AND bugnote_id=0';
}
- $t_query .= ' ORDER BY timestamp ASC';
+ $t_query .= ' ORDER BY id DESC';
$t_result = db_query_bound( $t_query, $t_params );
$t_revisions = array();
@@ -306,7 +307,7 @@ function bug_revision_list( $p_bug_id, $p_type=REV_ANY, $p_bugnote_id=0 ) {
/**
* Retrieve a list of changes to a bug of the same type as the
- * given revision ID.
+ * given revision ID, sorted in reverse chronological order.
* @param int $p_rev_id Revision ID
* @return array|null Array of Revision rows
*/
@@ -341,7 +342,7 @@ function bug_revision_like( $p_rev_id ) {
$t_query .= ' AND bugnote_id=0';
}
- $t_query .= ' ORDER BY timestamp ASC';
+ $t_query .= ' ORDER BY id DESC';
$t_result = db_query_bound( $t_query, $t_params );
$t_revisions = array();
Please sign in to comment.
Something went wrong with that request. Please try again.