Skip to content

Instantly share code, notes, and snippets.

@almaron
Last active August 29, 2015 14:27
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 almaron/c31f26fb7deefd0d23a5 to your computer and use it in GitHub Desktop.
Save almaron/c31f26fb7deefd0d23a5 to your computer and use it in GitHub Desktop.
def show
topic_ids = if (read = ForumTopicRead.find_by(user_id: current_user.id, forum_topic_id: 0))
ForumTopic.unscoped.joins("LEFT JOIN forum_topic_reads ON forum_topic_reads.forum_topic_id = forum_topics.id AND forum_topic_reads.user_id = #{current_user.id}").where(forum_id: params[:id]).where('forum_topics.last_post_at > ?', read.updated_at).group('forum_topics.id').having('count(forum_topic_reads.id) < 1').pluck(:id)
else
ForumTopic.unscoped.joins("LEFT JOIN forum_topic_reads ON forum_topic_reads.forum_topic_id = forum_topics.id AND forum_topic_reads.user_id = #{current_user.id}").where(forum_id: params[:id]).group('forum_topics.id').having('count(forum_topic_reads.id) < 1').pluck(:id)
end
render json: topic_ids
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment