Skip to content

Instantly share code, notes, and snippets.

@Epigene
Last active July 29, 2017 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Epigene/498ee5753460a4c6f92f37b110213c4c to your computer and use it in GitHub Desktop.
Save Epigene/498ee5753460a4c6f92f37b110213c4c to your computer and use it in GitHub Desktop.
The bad
last_post_ids = []
User.where(id: Post.all.distinct.pluck(:user_id)).find_each |user|
last_post_ids << user.posts.order(created_at: :desc).limit(1).pluck(:id).last
end
last_posts = Post.where(id: last_post_ids).order(created_at: :desc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment