Clean up usages of Mongoid to generate cleaner code / queries.
This commit is contained in:
Родитель
925dd72a9d
Коммит
db7235501f
|
@ -1,6 +1,7 @@
|
|||
require 'new_relic/agent/method_tracer'
|
||||
|
||||
get "#{APIPREFIX}/threads" do # retrieve threads by course
|
||||
|
||||
threads = Content.where({"_type" => "CommentThread", "course_id" => params["course_id"]})
|
||||
threads = CommentThread.where({"course_id" => params["course_id"]})
|
||||
if params[:commentable_ids]
|
||||
threads = threads.in({"commentable_id" => params[:commentable_ids].split(",")})
|
||||
end
|
||||
|
|
|
@ -28,10 +28,10 @@ module ThreadUtils
|
|||
thread_key = t._id.to_s
|
||||
if read_dates.has_key? thread_key
|
||||
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,
|
||||
:author_id => {"$ne" => user.id},
|
||||
:updated_at => {"$gte" => read_dates[thread_key]}
|
||||
:updated_at => {"$gte" => read_dates[thread_key]},
|
||||
).count
|
||||
read_states[thread_key] = [is_read, unread_comment_count]
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче