Why post_number?

I’ve noticed that all posts bear both a post_id and a post_number. I understand that post_id is the unique identifier of the post in the entire forum, while post_number is the number of the post in its topic. Posts identify themselves as replies to other posts by referencing the post_number of another post in the reply_to_post_number field. Whenever any topic (or section of posts from a topic) is retrieved from the server, it contains a sorted array of the post_id’s of every post in the topic. The front end provides access to specific post_numbers via the URL, but when such a URL is actually accessed the request made to the back end is in terms of post_ids (presumably accessed from the above mentioned array).

This is all well and good, but it seems like everything post_number is used for could be accomplished with post_id instead: post_id’s are always increasing, so they can be used to determine the relative ordering of posts in a topic. Since they are globally unique they are certainly unique within each topic, and so could be used in a reply_to_post_id that serves the same purpose as reply_to_post_number.

TLDR; What purpose does post_number serve that could not be easily accomplished with post_id? If there is none then removing it would streamline the data model, which would seem to be a good thing.

This allows Why post_number? to continue to work efficiently even if Why post_number? is deleted.

And Why post_number? is arguably much prettier than Why post_number? or https://meta.discourse.org/t/why-post-number/373873 which does not hint properly on the topic.


Thanks for getting back to me so quickly Sam :smile:

How would post_id not work for this scenario? It would seem that if 2 is deleted, the third post would become the second post, but its post_number does not change accordingly and is now wrong. Post_id would behave the same way in this scenario, except that it would not wrongfully identify what is now the second post in the thread as the third.

Agreed that it is a prettier URL.

And if post 2 is later undeleted after post 3 takes its place, does it then become post 1 1/2 ?


@Mittineague I do not believe that post_number is ever updated, even in the event of post deletions. If it were updated then deleting a post would result in every link to every post after that post being broken.

I have just deleted the post immediately before this, post_number 5. This was post_number 6 before the deletion, and it still is if you look at the JSON representation of this topic Why post_number?

I have a running discourse instance without the 24 hour deletion delay, and in my testing there the post_number remains the same after deleting preceding posts.

The post number is correct now, cause external links continue to work. If we ever renumbered links would break which would be terrible.

(post number, topic_id) is an alias for (post_id) which is used to keep urls looking just right.


That makes sense, but why is reply_to_post_number used to identify which post a post is a reply to? If post_number only exists to make URL’s look prettier, why is it the identifier that replies depend on? Wouldn’t it be more consistent to make replies depend on post_id, a much more fundamental identifier? You would have to check that a post with that post_id existed in the thread the reply was being posted in, but you already have to do that with post_number.

1 Like

Yeah, this is a historic artefact we may get to cleaning it up at some point.