Hi there,
Is it possible to order posts in the api response?
I’m looking to retrieve posts, sorted by “id”.
Thank you!
The discussion revolves around ordering posts by ID in the Discourse API. hkremer asks if posts can be sorted by ID, noting that chronological order may not align with ID assignment. RGJ and Falco clarify that the default ordering is by creation date and that IDs are assigned chronologically, though gaps may appear due to private messages or database failovers. Falco suggests that if the goal is to retrieve all posts, using a full backup or the Data Explorer Plugin may be more effective. riking explains that ID allocation involves batches of auto-incremented values, which can cause gaps during database failovers. hkremer appreciates the clarification.
Hi there,
Is it possible to order posts in the api response?
I’m looking to retrieve posts, sorted by “id”.
Thank you!
Also more specifically https://meta.discourse.org/posts.json
Thanks both.
Richard, I think your request is for topics, not posts.
Rafael has the right base, but I don’t think you can order by created date (I hope I’m wrong?).
And if you could, I don’t believe IDs are assigned to posts based on when they are created.
Anecdotally in our Discourse instance, we are seeing many examples of IDs being assigned to posts outside of their chronological order.
This becomes an issue when you try to pull all posts using the method discussed here. If we can’t order posts by ID then it becomes impossible.
The default ordering is the created date AFAIK.
They are.
The gaps in the order are posts your user can’t see, most likely posts inside PMs.
If your goal is to extract ALL the posts, loading a full backup in a local PostgreSQL instance or even using our Data Explorer Plugin may be easier.
Each Postgres leader grabs a bundle of, I believe, 32 auto increment IDs at once. If your database is large enough, then creations will alternate between bundles.
This also means that gaps will be created when you fail over a database.
Thank you! This is helpful context