How to resort a topic's messages by date?

AI-generated summary

The discussion revolves around ressorting a topic’s messages by date in Discourse. mreach has imported an older mailing list and found that the threads are disordered due to posts being imported in a different order than they were created. pfaffman explains that topics are sorted in post-id order and suggests re-running the import script after wiping the database to fix the issue. However, mreach finds this solution impractical as the posts have been in place for months.

Alternative solutions proposed include building a plugin to reorder post-ids or sorting threads by date as they are queried. pfaffman cautions that reordering post-ids could affect site performance, but mreach suggests it might not have a permanent impact. pfaffman agrees that deleting and recreating posts in the correct order would resolve the issue.

I’ve imported a large older mailing list into Discourse and found (after merging various threads that were not initially properly identified to be part of a parent thread) that threads have become disordered. Many earlier dated thread messages are being shown in Discourse AFTER parent threads that have earlier dates.

Is there a method to resort threads so that they are ordered by date from oldest (original post) to newest?

No. The problem is that topics are sorted in post-id order. And, as you have described, you have imported posts in an order other than the order that they should have been created. I am afraid that the only proper solution is to fix the import so that posts are imported in the proper order. It sounds like, though, that all you’d need to do is wipe the database and re-run the import script.

(Or other “solutions” include don’t care about the post order, it’s old stuff that no one is going to read anyway, and contrive to, for each topic, delete all of the existing posts and re-create them in the correct order.)

Hmm, these have been in place now for quite some months. I don’t really believe the deletion and reimportation is an appropriate solution. I wonder if we can build a plugin that will allow post-id reordering… hmm.

Oh. That’s too bad. Anything is possible, I suppose, but that will affect performance on the whole site forever..

You could conceivably delete those topics and the associated custom fields and then run the script again. You’d want to test very carefully on a staging site before you do it on your live data.

If the post-ids are reordered then I wouldn’t think it would permanently affect it. I suppose another option would be a plugin that would simply sort a thread by date as it’s queried…

Right. If you delete and recreate all the posts on the right order you’ll be all set.