in models/user.rb [37:111]
def to_hash(params={})
hash = as_document
.slice(USERNAME, EXTERNAL_ID)
if params[:complete]
hash = hash.merge!("subscribed_thread_ids" => subscribed_thread_ids,
"subscribed_commentable_ids" => [],
"subscribed_user_ids" => [],
"follower_ids" => [],
"id" => id,
"upvoted_ids" => upvoted_ids,
"downvoted_ids" => downvoted_ids,
"default_sort_key" => default_sort_key)
end
if params[:course_id]
self.class.trace_execution_scoped(['Custom/User.to_hash/count_comments_and_threads']) do
if not params[:group_ids].empty?
specified_groups_or_global = params[:group_ids] << nil
threads_count = CommentThread.course_context.where(
author_id: id,
course_id: params[:course_id],
group_id: {"$in" => specified_groups_or_global},
anonymous: false,
anonymous_to_peers: false
).count
comment_thread_ids = Comment.includes(:comment_thread).where(
author_id: id,
course_id: params[:course_id],
anonymous: false,
anonymous_to_peers: false
).
reject{ |comment| comment.standalone_context? }.
collect{ |comment| comment.comment_thread_id }
group_comment_thread_ids = CommentThread.where(
id: {"$in" => comment_thread_ids.uniq},
group_id: {"$in" => specified_groups_or_global},
).collect{|d| d.id}
comments_count = comment_thread_ids.count{
|comment_thread_id| group_comment_thread_ids.include?(comment_thread_id)
}
else
threads_count = CommentThread.course_context.where(
author_id: id,
course_id: params[:course_id],
anonymous: false,
anonymous_to_peers: false
).count
comments_count = Comment.includes(:comment_thread).where(
author_id: id,
course_id: params[:course_id],
anonymous: false,
anonymous_to_peers: false
).reject{ |comment| comment.standalone_context? }.count
end
hash = hash.merge!("threads_count" => threads_count, "comments_count" => comments_count)
end
end
hash
end