Commit 49336710 authored by Paco Guzman's avatar Paco Guzman

Use MergeRequestsClosingIssues cache data on Issue#closed_by_merge_requests method

parent c08435e3
...@@ -2,6 +2,8 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -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) ## 8.14.0 (2016-11-22)
- 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