Basic sort/limit option for post_stream


(Elliott Hebert) #1

Hi !

I was trying to fetch all the posts related to a topic and order them by created_date so the latest will be displayed first.

we are using the Ruby Gem.

our solution was to query the topic first, reverse the stream and fetch the 10 first ids, after we did an other query to fetch the correct posts using the topic_post method.

topic = project.get_ask_topic

posts_id = topic[“post_stream”][“stream”].reverse[0…10]
posts = DISCOURSE_CLIENT.topic_posts(project.ask_topic_id, @posts_id)
posts = posts[“post_stream”][“posts”].reverse

I am just wondering why the API doesn’t have a possible :order params and :limit params to fetch to correct data at once.

I’am happy to help to implement that !