summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-03-18 12:47:36 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2016-03-19 21:54:08 +0100
commit41b8d22631053e66043d05695d65f4961b91efd8 (patch)
treef598203c809c87e4997e475055b6c592a9aecb42
parent3f22a92f4a561543c2249786b695d0c65120455b (diff)
downloadgitlab-ce-41b8d22631053e66043d05695d65f4961b91efd8.tar.gz
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.
-rw-r--r--app/models/issue.rb6
-rw-r--r--spec/models/issue_spec.rb4
2 files changed, 5 insertions, 5 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 5347d4fa1be..af80dee1dc4 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -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
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 540a62eb1f8..77d046fb0eb 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -133,9 +133,9 @@ describe Issue, models: true do
describe '#related_branches' do
it "selects the right branches" do
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