summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-10-19 14:30:17 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-10-20 12:55:14 +0200
commit493367108eef14c8517c6d023ec46267c1e706cf (patch)
tree62ae94fac2284b8424bc4e0abbe3acdda3874982
parentc08435e3c25f0a7a705ed8a49b16dde176b41a40 (diff)
downloadgitlab-ce-493367108eef14c8517c6d023ec46267c1e706cf.tar.gz
Use MergeRequestsClosingIssues cache data on Issue#closed_by_merge_requests method14192-issues-closed-by-merge-requests-using-metrics-data
-rw-r--r--CHANGELOG.md2
-rw-r--r--app/models/issue.rb8
-rw-r--r--spec/models/issue_spec.rb8
3 files changed, 16 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b018fc0d57..6c0fd97b070 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@ Please view this file on the master branch, on stable branches it's out of date.
## 8.14.0 (2016-11-22)
+ - Use MergeRequestsClosingIssues cache data on Issue#closed_by_merge_requests method
+
## 8.13.0 (2016-10-22)
- Fix save button on project pipeline settings page. (!6955)
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 133a5993815..89158a50353 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -211,7 +211,13 @@ class Issue < ActiveRecord::Base
note.all_references(current_user, extractor: ext)
end
- ext.merge_requests.select { |mr| mr.open? && mr.closes_issue?(self) }
+ merge_requests = ext.merge_requests.select(&:open?)
+ if merge_requests.any?
+ ids = MergeRequestsClosingIssues.where(merge_request_id: merge_requests.map(&:id), issue_id: id).pluck(:merge_request_id)
+ merge_requests.select { |mr| mr.id.in?(ids) }
+ else
+ []
+ end
end
def moved?
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 3b8b743af2d..60d30eb7418 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -100,11 +100,17 @@ describe Issue, models: true do
end
it 'returns the merge request to close this issue' do
- allow(mr).to receive(:closes_issue?).with(issue).and_return(true)
+ mr
expect(issue.closed_by_merge_requests).to eq([mr])
end
+ it "returns an empty array when the merge request is closed already" do
+ closed_mr
+
+ expect(issue.closed_by_merge_requests).to eq([])
+ end
+
it "returns an empty array when the current issue is closed already" do
expect(closed_issue.closed_by_merge_requests).to eq([])
end