diff options
author | Felipe Artur <felipefac@gmail.com> | 2017-01-23 18:40:25 -0200 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-02-09 17:40:37 -0200 |
commit | 0b14b654b6e5d936f7241dcc0c249e0d4cc42728 (patch) | |
tree | 714fff562236a7cbc78d837cea8ff7a648923166 /app/models/award_emoji.rb | |
parent | c4fd6ff407cff8f2f742997a7400ba940a1fce5f (diff) | |
download | gitlab-ce-0b14b654b6e5d936f7241dcc0c249e0d4cc42728.tar.gz |
Gather issuable metadata to avoid n+ queries on index viewissue_25900_2
Diffstat (limited to 'app/models/award_emoji.rb')
-rw-r--r-- | app/models/award_emoji.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/award_emoji.rb b/app/models/award_emoji.rb index 46b17479d6d..6937ad3bdd9 100644 --- a/app/models/award_emoji.rb +++ b/app/models/award_emoji.rb @@ -16,6 +16,14 @@ class AwardEmoji < ActiveRecord::Base scope :downvotes, -> { where(name: DOWNVOTE_NAME) } scope :upvotes, -> { where(name: UPVOTE_NAME) } + class << self + def votes_for_collection(ids, type) + select('name', 'awardable_id', 'COUNT(*) as count'). + where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids). + group('name', 'awardable_id') + end + end + def downvote? self.name == DOWNVOTE_NAME end |