diff options
author | Paco Guzman <pacoguzmanp@gmail.com> | 2016-06-14 17:48:39 +0300 |
---|---|---|
committer | Paco Guzman <pacoguzmanp@gmail.com> | 2016-06-15 07:50:12 +0300 |
commit | 52a2b8a41001b35338bcc6d92fa4c9679c4196a8 (patch) | |
tree | 32d866b4a44ee0c301e752a8e7ae9b58467865c0 /app/models/concerns/awardable.rb | |
parent | bf4455d14659f1fde6391164b38310d361bf407d (diff) |
Include user relationship when retrieving award_emoji
Avoiding N+1 when showing grouped awards and when
calculating participants for awardable entities
Diffstat (limited to 'app/models/concerns/awardable.rb')
-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] ||= [] |