Merge pull request #200 from edx/perf/n-plus-one-use-relations

Use proper relations instead of forcefully loading relations by hand.
This commit is contained in:
Toby Lawrence 2016-08-18 14:40:48 -04:00 коммит произвёл GitHub
Родитель bfd866c10f a89ce19171
Коммит 14ed8a85c6
1 изменённых файлов: 6 добавлений и 19 удалений

Просмотреть файл

@ -117,35 +117,22 @@ class Comment < Content
end
def commentable_id
#we need this to have a universal access point for the flag rake task
if self.comment_thread_id
t = CommentThread.find self.comment_thread_id
if t
t.commentable_id
end
end
return nil unless self.comment_thread
self.comment_thread.commentable_id
rescue Mongoid::Errors::DocumentNotFound
nil
end
def group_id
if self.comment_thread_id
t = CommentThread.find self.comment_thread_id
if t
t.group_id
end
end
return nil unless self.comment_thread
self.comment_thread.group_id
rescue Mongoid::Errors::DocumentNotFound
nil
end
def context
if self.comment_thread_id
t = CommentThread.find self.comment_thread_id
if t
t.context
end
end
return nil unless self.comment_thread
self.comment_thread.context
rescue Mongoid::Errors::DocumentNotFound
nil
end