summaryrefslogtreecommitdiff
path: root/app/models/concerns
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-24 12:49:34 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-24 12:49:34 +0200
commita5f23435f7d8b8040ed6b80322ccea3fa8323468 (patch)
treeb42573e97f626add0f7d8e108b82a89de2ea3364 /app/models/concerns
parentc83bbfa79e6cfaefc21b0eaaa93370d8748e9aab (diff)
downloadgitlab-ce-a5f23435f7d8b8040ed6b80322ccea3fa8323468.tar.gz
Improve performance for issue#show page
* store @participants in variable * store result of subscribed? call into variable In total it reduce amount of SQL queries for issue with 10 comments/participants twice. Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/models/concerns')
-rw-r--r--app/models/concerns/participable.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb
index 9f667f47e0d..7c9597333dd 100644
--- a/app/models/concerns/participable.rb
+++ b/app/models/concerns/participable.rb
@@ -14,7 +14,7 @@
#
# participant :author, :assignee, :mentioned_users, :notes
# end
-#
+#
# issue = Issue.last
# users = issue.participants
# # `users` will contain the issue's author, its assignee,
@@ -35,11 +35,13 @@ module Participable
end
end
+ # Be aware that this method makes a lot of sql queries.
+ # Save result into variable if you are going to reuse it inside same request
def participants(current_user = self.author, project = self.project)
participants = self.class.participant_attrs.flat_map do |attr|
meth = method(attr)
- value =
+ value =
if meth.arity == 1 || meth.arity == -1
meth.call(current_user)
else
@@ -59,7 +61,7 @@ module Participable
end
private
-
+
def participants_for(value, current_user = nil, project = nil)
case value
when User