From 4fcb52cd45cb03398e821e73dd85c2df19c4a6c6 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 1 Oct 2023 18:29:20 +0200 Subject: [PATCH] MDL-79247 forum: Make discussion list ordering deterministic Note that normally this doesn't matter much, but there are situations when we want the discussion list ordering fully consistent / deterministic. Specifically, when discussions (or forum posts )are created in the same second, or when the discussion titles are repeated, or 2 discussions have the same number of votes... (any criteria in general), in the context of testing, we don't want the order to be non-consistent, so we need to provide an extra sorting criterion to make it fully deterministic. So, in this case, we are adding a sort by discussion.id <> that is an unique value, primary key... so cheap to calculate and, that way, when the 1st sorting column has repeated values, the id will decide. --- mod/forum/classes/local/vaults/discussion_list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/forum/classes/local/vaults/discussion_list.php b/mod/forum/classes/local/vaults/discussion_list.php index 41866143d3c..e099a671ae0 100644 --- a/mod/forum/classes/local/vaults/discussion_list.php +++ b/mod/forum/classes/local/vaults/discussion_list.php @@ -350,7 +350,7 @@ class discussion_list extends db_table_vault { $favouritesort .= ", {$favalias}.itemtype DESC"; } - return "{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}"; + return "{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}, {$alias}.id {$direction}"; } /**