Commit 60adbef4 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch '14192-issues-closed-by-merge-requests-using-metrics-data' into 'master'

Use MergeRequestsClosingIssues cache data on Issue#closed_by_merge_requests method

See merge request !6996
parents e647af36 49336710
...@@ -7,6 +7,8 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -7,6 +7,8 @@ Please view this file on the master branch, on stable branches it's out of date.
- Simpler arguments passed to named_route on toggle_award_url helper method - Simpler arguments passed to named_route on toggle_award_url helper method
- Fix: Backup restore doesn't clear cache - Fix: Backup restore doesn't clear cache
- Use MergeRequestsClosingIssues cache data on Issue#closed_by_merge_requests method
## 8.13.0 (2016-10-22) ## 8.13.0 (2016-10-22)
- Fix save button on project pipeline settings page. (!6955) - Fix save button on project pipeline settings page. (!6955)
......
...@@ -211,7 +211,13 @@ class Issue < ActiveRecord::Base ...@@ -211,7 +211,13 @@ class Issue < ActiveRecord::Base
note.all_references(current_user, extractor: ext) note.all_references(current_user, extractor: ext)
end 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 end
def moved? def moved?
......
...@@ -100,11 +100,17 @@ describe Issue, models: true do ...@@ -100,11 +100,17 @@ describe Issue, models: true do
end end
it 'returns the merge request to close this issue' do 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]) expect(issue.closed_by_merge_requests).to eq([mr])
end 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 it "returns an empty array when the current issue is closed already" do
expect(closed_issue.closed_by_merge_requests).to eq([]) expect(closed_issue.closed_by_merge_requests).to eq([])
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment