diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-25 08:14:03 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-25 08:14:03 +0000 |
commit | 0c8b96bdbc5c9f92d7a1e1227498cd2cc00d19ac (patch) | |
tree | 63e9d6828b43e8c4f8d01d137cb1ebb3b8fab50d /app/models | |
parent | d2de219f6cf5d6ce371f529988f9337653878e58 (diff) | |
parent | 82f372c719b7564fa09f23bef1e6d4c61c8ece4b (diff) | |
download | gitlab-ce-0c8b96bdbc5c9f92d7a1e1227498cd2cc00d19ac.tar.gz |
Merge branch 'performance-improvements' into 'master'
Performance improvements
* store @participants in variable
* store result of subscribed? call into variable
In total it reduce amount of SQL queries for issue or merge_request with 10 comments/participants almost twice.
See merge request !883
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/concerns/participable.rb | 8 |
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 |