From c951d69b86482814759a858af9cb6a70576f20da Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Thu, 22 Jan 2015 18:06:19 +0100 Subject: [PATCH] Sort bugnotes by date_submitted Previously they were sorted by id. The date_submitted column is currently not indexed. I tested the new code both with and without adding an index; the explain plan was identical, and I did not measure any meaningful difference in query execution time, even for bugs having a large number of bugnotes (tested with #4286 which has 648 bugnotes). Fixes #11742 --- core/bugnote_api.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/bugnote_api.php b/core/bugnote_api.php index 6e7120b529..803e2199ae 100644 --- a/core/bugnote_api.php +++ b/core/bugnote_api.php @@ -423,13 +423,14 @@ function bugnote_get_all_bugnotes( $p_bug_id ) { $t_bugnote_table = db_get_table( 'mantis_bugnote_table' ); $t_bugnote_text_table = db_get_table( 'mantis_bugnote_text_table' ); - # sort by bugnote id which should be more accurate than submit date, since two bugnotes - # may be submitted at the same time if submitted using a script (eg: MantisConnect). + # Now sorting by submit date and id (#11742). The date_submitted + # column is currently not indexed, but that does not seem to affect + # performance in a measurable way $t_query = "SELECT b.*, t.note FROM $t_bugnote_table b LEFT JOIN $t_bugnote_text_table t ON b.bugnote_text_id = t.id WHERE b.bug_id=" . db_param() . ' - ORDER BY b.id ASC'; + ORDER BY b.date_submitted ASC, b.id ASC'; $t_bugnotes = array(); # BUILD bugnotes array