From 1eb72a71f54da310b2277e5890dce27c15e11036 Mon Sep 17 00:00:00 2001
From: blackst0ne <blackst0ne.ru@gmail.com>
Date: Tue, 21 Feb 2017 12:45:08 +1100
Subject: [PATCH] Refactored count_for_collection() for using pluck instead of
 select

---
 app/controllers/concerns/issuable_collections.rb | 4 ++--
 app/models/merge_requests_closing_issues.rb      | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb
index d7d781cbe72..85ae4985e58 100644
--- a/app/controllers/concerns/issuable_collections.rb
+++ b/app/controllers/concerns/issuable_collections.rb
@@ -28,13 +28,13 @@ module IssuableCollections
       downvotes = issuable_votes_count.find { |votes| votes.awardable_id == id && votes.downvote? }
       upvotes = issuable_votes_count.find { |votes| votes.awardable_id == id && votes.upvote? }
       notes = issuable_note_count.find { |notes| notes.noteable_id == id }
-      merge_requests = issuable_merge_requests_count.find { |mr| mr.issue_id == id }
+      merge_requests = issuable_merge_requests_count.find { |mr| mr.first == id }
 
       issuable_meta[id] = Issuable::IssuableMeta.new(
         upvotes.try(:count).to_i,
         downvotes.try(:count).to_i,
         notes.try(:count).to_i,
-        merge_requests.try(:count).to_i
+        merge_requests.try(:last).to_i
       )
     end
   end
diff --git a/app/models/merge_requests_closing_issues.rb b/app/models/merge_requests_closing_issues.rb
index 1ecdfd1dfdb..97210900bd5 100644
--- a/app/models/merge_requests_closing_issues.rb
+++ b/app/models/merge_requests_closing_issues.rb
@@ -7,9 +7,9 @@ class MergeRequestsClosingIssues < ActiveRecord::Base
 
   class << self
     def count_for_collection(ids)
-      select('issue_id', 'COUNT(*) as count').
-        group(:issue_id).
-        where(issue_id: ids)
+      group(:issue_id).
+      where(issue_id: ids).
+      pluck('issue_id', 'COUNT(*) as count')
     end
   end
 end
-- 
GitLab