Skip to content

[3.0] Lists the posts to split off a topic in a defined order - #9714

Merged
jdarwood007 merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/split-topic-message-order
Oct 4, 2026
Merged

jdarwood007 merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/split-topic-message-order

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

The page for choosing which posts to split off a topic lists them in no particular order on PostgreSQL.

All four queries behind it (TopicSplit, the page itself and its xml refresh, for the selected and the not selected lists) only added ORDER BY when the member views topics newest first:

' . (empty(Theme::$current->options['view_newest_first']) ? '' : 'ORDER BY id_msg DESC') . '

Otherwise the order was the database's choice. MySQL happens to return InnoDB rows in primary key order, which is why this has gone unnoticed since 2.1 (v2.1.7 has the same line). PostgreSQL returns rows in the order they sit in the table, and an UPDATE writes a row's new version at the end, so a post that has been edited is listed after the posts that came after it. Because the same queries use LIMIT, the order also decides which posts land on which page of the list, so a post can appear on two pages and be missing from another.

The queries now always order by the message id, descending for members who view newest first:

ORDER BY id_msg' . (empty(Theme::$current->options['view_newest_first']) ? '' : ' DESC') . '
Test

TopicSplitTest posts a topic and two replies through the posting form, edits the first post in the database, and checks the split page lists the three oldest first. The edit is what makes PostgreSQL misorder the list; on MySQL the test passes either way. Without the change, on PostgreSQL:

the posts to split are not listed oldest first
-    0 => 248,
+    0 => 250,
     1 => 249,
-    2 => 250,
+    2 => 248,

With it, it passes on both MySQL and PostgreSQL.

Found while building the template snapshot tests in #9712, where the split page's snapshot changed order on PostgreSQL between two runs.

Issues References (Fixes|Related|Closes)

Related: #9712

🤖 Generated with Claude Code

The queries behind the split page only said ORDER BY when the member
views topics newest first, and otherwise left the order to the database.
MySQL happens to return InnoDB rows in primary key order, so it never
showed there. PostgreSQL returns them in the order they sit in the
table, so an edited post was listed after later ones, and with LIMIT on
the same queries a post could appear on two pages of the list and be
missing from another. They now always order by the message id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@jdarwood007 jdarwood007 added this to the 3.0 Alpha 5 milestone Oct 4, 2026
@jdarwood007
jdarwood007 merged commit 5d0f330 into SimpleMachines:release-3.0 Oct 4, 2026
11 checks passed
jdarwood007 pushed a commit that referenced this pull request Oct 31, 2026
The four queries behind the split page only ordered by message id for
members who view topics newest first. Otherwise the order was the
database's, which on PostgreSQL puts an edited post last, and with LIMIT
decides which posts land on which page.

Backport of #9714.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants