From c0587ac3a4ea6f81747f1cb7bbc2f888b8162007 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 1 Oct 2023 18:29:20 +0200 Subject: [PATCH 1/2] 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}"; } /** From 7db3ed235bd9d7ad512feb4000088022ddca2efa Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 1 Oct 2023 23:23:30 +0200 Subject: [PATCH 2/2] MDL-79247 forum: Workaround same-time discussion modified dates bug Within the forum_get_discussion_neighbours() function of forum when the discussions timemodified (last post) is the same, there is a bug that does strange things when calculating the prev and next discussions. Note that, in real life, this is really hard to achieve, but in tests, when multiple discussions and post can be created by generators in the same second (specially when the test machine is quick), chances of facing that problem are higher. By adding 1 second wait, we ensure that the discussions won't have the same timemodified (last post) and workaround the problem. No mater of that, the problem deserves an issue to be created so we guarantee from code that it also works ok when the same timemodified (last post) situation happens. --- mod/forum/tests/behat/discussion_navigation.feature | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mod/forum/tests/behat/discussion_navigation.feature b/mod/forum/tests/behat/discussion_navigation.feature index 4caa84a7081..045547a63d0 100644 --- a/mod/forum/tests/behat/discussion_navigation.feature +++ b/mod/forum/tests/behat/discussion_navigation.feature @@ -51,6 +51,11 @@ Feature: A user can navigate to previous and next discussions And I follow "Reply" And I set the following fields to these values: | Message | Answer to discussion | + # We need to wait a bit to guarantee that the post is created after the previous ones. + # because there is a bug in the forum_get_discussion_neighbours() when all the discussion + # last modified times are the same. See MDL-79247 for more details. Once that bug is fixed + # we can remove this wait. + And I wait "1" seconds And I press "Post to forum" And I should not see "Discussion 2" And I should see "Discussion 3"