After recently updating to 2.6.0.beta3 some replies in various threads are showing in the wrong order. The time stamps show correctly, but the affected replies are always at the bottom of the thread.
I have tried updating again, and running rake posts:reorder_posts on the affected topics, but this has had no effect. Is there anything else I can do to get them to re-order correctly? Or is this a bug in discourse? The posts display the same for all users.
An example from one of the topics, this is the bottom of the thread:
Running the query from posts:reorder_posts shows that the sort_order for a number of posts is odd, and looks like the rake should update them, but it does not.
In trying to manually re-create the rake task, I’ve run:
WITH ordered_posts AS (
SELECT
id,
ROW_NUMBER() OVER (
PARTITION BY
topic_id
ORDER BY
created_at,
post_number
) AS new_post_number
FROM
posts
/*where*/
)
SELECT
p.post_number,
p.sort_order,
o.new_post_number
FROM
posts AS p, ordered_posts AS o
WHERE
p.id = o.id
resulting in:
Which shows why the rake task does nothing - it thinks there is nothing to do… The rake task has an additional where comparing post_number to new_post_number, and not sort_order.
I have now run:
WITH ordered_posts AS (
SELECT
id,
ROW_NUMBER() OVER (
PARTITION BY
topic_id
ORDER BY
created_at,
post_number
) AS new_post_number
FROM
posts
/*where*/
)
UPDATE
posts AS p
SET
sort_order = o.new_post_number
FROM
ordered_posts AS o
WHERE
p.id = o.id AND
p.sort_order <> o.new_post_number
on the database manually, and the posts now appear in the correct order.
I don’t understand it either, I couldn’t find any reason for it when looking through the code. Something seems to modify the sort order, but I can’t see what.
I thought that they had gone out of order when I ran an upgrade, as the messages that were out of order were generally much older, and had previously appeared in an expected place. When I fan the SQL above all seemed well, but then the other week a couple of brand new posts have also now appeared out of order. I think the posts it affects are always replies to another post. eg:
I have the same issue. I have previously had 502 errors when moving posts due to long topics, not sure if that has anything to do with it. I also have the question-answer plugin installed but I’m still seeing posts appearing at the bottom of topics after disabling it.
Very likely, this is not really a supported or official plugin, sort_order is only used inconsistently in discourse core, we are considering removing this column.
Moving this to support cause I see this as a bug in a non official plugin.
@angus Can you take a look at this issue? I installed this plugin and replies started to appear out of order for the entire site. I just removed the plugin and replies still appear out of order.
I’ve run a test on a single post to see if the following command will correct the out of order replies in a single post (after removing the Q&A plugin).
rake posts:reorder_posts[1896]
Unfortunately posts are still appearing out of order.
Hey, sorry you’ve experienced this issue. Please post any updates on this in Question Answer Plugin. @mbcahyono and or I will respond shortly. This is not a general Discourse support question.