Commit 5bf64eb0 by David Ormsbee

Make User model do more work in the DB layer

parent 9b188b87
...@@ -31,23 +31,23 @@ class User ...@@ -31,23 +31,23 @@ class User
end end
def subscribed_thread_ids def subscribed_thread_ids
subscriptions_as_subscriber.where(source_type: "CommentThread").map(&:source_id) subscriptions_as_subscriber.where(source_type: "CommentThread").only(:source_id).map(&:source_id)
end end
def subscribed_commentable_ids def subscribed_commentable_ids
subscriptions_as_subscriber.where(source_type: "Commentable").map(&:source_id) subscriptions_as_subscriber.where(source_type: "Commentable").only(:source_id).map(&:source_id)
end end
def subscribed_user_ids def subscribed_user_ids
subscriptions_as_subscriber.where(source_type: "User").map(&:source_id) subscriptions_as_subscriber.where(source_type: "User").only(:source_id).map(&:source_id)
end end
def subscribed_threads def subscribed_threads
subscribed_thread_ids.map {|id| CommentThread.find(id)} CommentThread.where(:id.in => subscribed_thread_ids).without(:body)
end end
def subscribed_commentables def subscribed_commentables
subscribed_commentable_ids.map {|id| Commentable.find(id)} Commentable.where(:id.in => subscribed_commentable_ids).only(:id).map(&:id)
end end
def subscribed_users def subscribed_users
...@@ -60,7 +60,7 @@ class User ...@@ -60,7 +60,7 @@ class User
hash = hash.merge("subscribed_thread_ids" => subscribed_thread_ids, hash = hash.merge("subscribed_thread_ids" => subscribed_thread_ids,
"subscribed_commentable_ids" => subscribed_commentable_ids, "subscribed_commentable_ids" => subscribed_commentable_ids,
"subscribed_user_ids" => subscribed_user_ids, "subscribed_user_ids" => subscribed_user_ids,
"follower_ids" => subscriptions_as_source.map(&:subscriber_id), "follower_ids" => subscriptions_as_source.only(:subscriber_id).map(&:subscriber_id),
"id" => id, "id" => id,
"upvoted_ids" => upvoted_ids, "upvoted_ids" => upvoted_ids,
"downvoted_ids" => downvoted_ids, "downvoted_ids" => downvoted_ids,
......
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