Last active
August 29, 2015 14:27
-
-
Save almaron/c31f26fb7deefd0d23a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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