Commit c8204217 by David Ormsbee

Add a few more indexes, make some explicit queries to make sure we're using those indexes.

parent 2fd29112
......@@ -15,6 +15,8 @@ class Comment < Content
field :anonymous, type: Boolean, default: false
field :at_position_list, type: Array, default: []
index({author_id: 1, course_id: 1})
belongs_to :comment_thread, index: true
belongs_to :author, class_name: "User", index: true
......
......@@ -21,6 +21,8 @@ class CommentThread < Content
field :at_position_list, type: Array, default: []
field :last_activity_at, type: Time
index({author_id: 1, course_id: 1})
include Tire::Model::Search
include Tire::Model::Callbacks
......
......@@ -7,6 +7,8 @@ class Subscription
field :source_type, type: String
index({subscriber_id: 1, source_id: 1, source_type: 1})
index({subscriber_id: 1, source_type: 1})
index({subscriber_id: 1})
def to_hash
as_document.slice(*%w[subscriber_id source_id source_type])
......
......@@ -31,7 +31,7 @@ class User
end
def subscribed_thread_ids
subscriptions_as_subscriber.where(source_type: "CommentThread").only(:source_id).map(&:source_id)
Subscription.where(subscriber_id: id.to_s, source_type: "CommentThread").only(:source_id).map(&:source_id)
end
def subscribed_commentable_ids
......@@ -47,7 +47,7 @@ class User
end
def subscribed_commentables
Commentable.where(:id.in => subscribed_commentable_ids).only(:id).map(&:id)
Commentable.find(*subscribed_commentable_ids).only(:id).map(&:id)
end
def subscribed_users
......@@ -64,11 +64,12 @@ class User
"id" => id,
"upvoted_ids" => upvoted_ids,
"downvoted_ids" => downvoted_ids,
"default_sort_key" => default_sort_key)
"default_sort_key" => default_sort_key
)
end
if params[:course_id]
hash = hash.merge("threads_count" => comment_threads.where(course_id: params[:course_id]).count,
"comments_count" => comments.where(course_id: params[:course_id]).count,
hash = hash.merge("threads_count" => CommentThread.where(user_id: id, course_id: params[:course_id]).count,
"comments_count" => Comment.where(user_id: id, course_id: params[:course_id]).count
)
end
hash
......
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