Commit db723550 by Toby Lawrence

Clean up usages of Mongoid to generate cleaner code / queries.

parent 925dd72a
get "#{APIPREFIX}/threads" do # retrieve threads by course require 'new_relic/agent/method_tracer'
threads = Content.where({"_type" => "CommentThread", "course_id" => params["course_id"]}) get "#{APIPREFIX}/threads" do # retrieve threads by course
threads = CommentThread.where({"course_id" => params["course_id"]})
if params[:commentable_ids] if params[:commentable_ids]
threads = threads.in({"commentable_id" => params[:commentable_ids].split(",")}) threads = threads.in({"commentable_id" => params[:commentable_ids].split(",")})
end end
......
...@@ -28,10 +28,10 @@ module ThreadUtils ...@@ -28,10 +28,10 @@ module ThreadUtils
thread_key = t._id.to_s thread_key = t._id.to_s
if read_dates.has_key? thread_key if read_dates.has_key? thread_key
is_read = read_dates[thread_key] >= t.updated_at is_read = read_dates[thread_key] >= t.updated_at
unread_comment_count = Comment.collection.find( unread_comment_count = Comment.where(
:comment_thread_id => t._id, :comment_thread_id => t._id,
:author_id => {"$ne" => user.id}, :author_id => {"$ne" => user.id},
:updated_at => {"$gte" => read_dates[thread_key]} :updated_at => {"$gte" => read_dates[thread_key]},
).count ).count
read_states[thread_key] = [is_read, unread_comment_count] read_states[thread_key] = [is_read, unread_comment_count]
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment