diff options
author | Paco Guzman <pacoguzmanp@gmail.com> | 2016-06-14 16:48:39 +0200 |
---|---|---|
committer | Paco Guzman <pacoguzmanp@gmail.com> | 2016-06-15 06:50:12 +0200 |
commit | 52a2b8a41001b35338bcc6d92fa4c9679c4196a8 (patch) | |
tree | 32d866b4a44ee0c301e752a8e7ae9b58467865c0 /app | |
parent | bf4455d14659f1fde6391164b38310d361bf407d (diff) | |
download | gitlab-ce-52a2b8a41001b35338bcc6d92fa4c9679c4196a8.tar.gz |
Include user relationship when retrieving award_emoji14320-note-grouped_awards
Avoiding N+1 when showing grouped awards and when
calculating participants for awardable entities
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/awardable.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/app/models/concerns/awardable.rb b/app/models/concerns/awardable.rb index aa4b4201250..539c7c31e30 100644 --- a/app/models/concerns/awardable.rb +++ b/app/models/concerns/awardable.rb @@ -5,7 +5,7 @@ module Awardable has_many :award_emoji, as: :awardable, dependent: :destroy if self < Participable - participant :award_emoji + participant :award_emoji_with_associations end end @@ -34,8 +34,12 @@ module Awardable end end + def award_emoji_with_associations + award_emoji.includes(:user) + end + def grouped_awards(with_thumbs: true) - awards = award_emoji.group_by(&:name) + awards = award_emoji_with_associations.group_by(&:name) if with_thumbs awards[AwardEmoji::UPVOTE_NAME] ||= [] |