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:
parent
3f22a92f4a
commit
41b8d22631
2 changed files with 5 additions and 5 deletions
|
@ -105,9 +105,9 @@ class Issue < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def related_branches
|
||||
return [] if self.project.empty_repo?
|
||||
|
||||
self.project.repository.branch_names.select { |branch| branch.end_with?("-#{iid}") }
|
||||
project.repository.branch_names.select do |branch|
|
||||
branch.end_with?("-#{iid}")
|
||||
end
|
||||
end
|
||||
|
||||
# Reset issue events cache
|
||||
|
|
|
@ -135,7 +135,7 @@ describe Issue, models: true do
|
|||
allow(subject.project.repository).to receive(:branch_names).
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue