Skip to content

Commit

Permalink
MDL-79247 forum: Make discussion list ordering deterministic
Browse files Browse the repository at this point in the history
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 <<DIRECTION>>
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.
  • Loading branch information
stronk7 committed Oct 1, 2023
1 parent ea288b3 commit 3f47f81
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mod/forum/classes/local/vaults/discussion_list.php
Expand Up @@ -347,7 +347,7 @@ private function get_sort_order(?int $sortmethod, bool $includefavourites = true
$favouritesort .= ", {$favalias}.itemtype DESC";
}

return "{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}";
return "{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}, {$alias}.id {$direction}";
}

/**
Expand Down

0 comments on commit 3f47f81

Please sign in to comment.