Tweaked performance of Issue#related_branches

Requesting the branch names of a repository works even when it's empty,
thus there's no need to explicitly check for an empty repository.
Removing this check cuts down the amount of Git operations which in turn
cuts down request timings a bit. The regular expression used to compare
branches was also moved out of the loop so it's created only once.
This commit is contained in:
Yorick Peterse 2016-03-18 12:47:36 +01:00
parent 3f22a92f4a
commit 41b8d22631
2 changed files with 5 additions and 5 deletions

View file

@ -105,9 +105,9 @@ class Issue < ActiveRecord::Base
end end
def related_branches def related_branches
return [] if self.project.empty_repo? project.repository.branch_names.select do |branch|
branch.end_with?("-#{iid}")
self.project.repository.branch_names.select { |branch| branch.end_with?("-#{iid}") } end
end end
# Reset issue events cache # Reset issue events cache

View file

@ -133,9 +133,9 @@ describe Issue, models: true do
describe '#related_branches' do describe '#related_branches' do
it "selects the right branches" do it "selects the right branches" do
allow(subject.project.repository).to receive(:branch_names). allow(subject.project.repository).to receive(:branch_names).
and_return(["mpempe", "#{subject.iid}mepmep", subject.to_branch_name]) and_return(["mpempe", "#{subject.iid}mepmep", subject.to_branch_name])
expect(subject.related_branches).to eq [subject.to_branch_name] expect(subject.related_branches).to eq([subject.to_branch_name])
end end
end end