Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2017-01-23 23:40:25 +0300
committerFelipe Artur <felipefac@gmail.com>2017-02-09 22:40:37 +0300
commit0b14b654b6e5d936f7241dcc0c249e0d4cc42728 (patch)
tree714fff562236a7cbc78d837cea8ff7a648923166 /app/models/award_emoji.rb
parentc4fd6ff407cff8f2f742997a7400ba940a1fce5f (diff)
Gather issuable metadata to avoid n+ queries on index view
Diffstat (limited to 'app/models/award_emoji.rb')
-rw-r--r--app/models/award_emoji.rb8
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