summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-12-28 08:02:43 +0000
committerSean McGivern <sean@gitlab.com>2018-12-28 08:02:43 +0000
commit5c9aa170bf0be2e6c23535ef82b80b914fc4089b (patch)
tree5819c55a472e48ea67e35bbdf6a5a4aa420a3179
parentf13ec30d5e0079d66efadd374b219d0c445e28cf (diff)
parente7bd824484636fd4d4d7beb524b6bea3ecef533a (diff)
downloadgitlab-ce-5c9aa170bf0be2e6c23535ef82b80b914fc4089b.tar.gz
Merge branch 'sh-fix-branches-api-timeout' into 'master'
Fix timeout issues retrieving branches via API Closes #55724 See merge request gitlab-org/gitlab-ce!24034
-rw-r--r--changelogs/unreleased/sh-fix-branches-api-timeout.yml5
-rw-r--r--lib/api/branches.rb4
-rw-r--r--spec/requests/api/branches_spec.rb12
3 files changed, 19 insertions, 2 deletions
diff --git a/changelogs/unreleased/sh-fix-branches-api-timeout.yml b/changelogs/unreleased/sh-fix-branches-api-timeout.yml
new file mode 100644
index 00000000000..8cd29a7269d
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-branches-api-timeout.yml
@@ -0,0 +1,5 @@
+---
+title: Fix timeout issues retrieving branches via API
+merge_request: 24034
+author:
+type: performance
diff --git a/lib/api/branches.rb b/lib/api/branches.rb
index e7e58ad0e66..07f529b01bb 100644
--- a/lib/api/branches.rb
+++ b/lib/api/branches.rb
@@ -34,11 +34,11 @@ module API
repository = user_project.repository
branches = BranchesFinder.new(repository, declared_params(include_missing: false)).execute
-
+ branches = ::Kaminari.paginate_array(branches)
merged_branch_names = repository.merged_branch_names(branches.map(&:name))
present(
- paginate(::Kaminari.paginate_array(branches)),
+ paginate(branches),
with: Entities::Branch,
current_user: current_user,
project: user_project,
diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb
index 93c411476bb..b38cd66986f 100644
--- a/spec/requests/api/branches_spec.rb
+++ b/spec/requests/api/branches_spec.rb
@@ -20,6 +20,12 @@ describe API::Branches do
let(:route) { "/projects/#{project_id}/repository/branches" }
shared_examples_for 'repository branches' do
+ RSpec::Matchers.define :has_merged_branch_names_count do |expected|
+ match do |actual|
+ actual[:merged_branch_names].count == expected
+ end
+ end
+
it 'returns the repository branches' do
get api(route, current_user), params: { per_page: 100 }
@@ -30,6 +36,12 @@ describe API::Branches do
expect(branch_names).to match_array(project.repository.branch_names)
end
+ it 'determines only a limited number of merged branch names' do
+ expect(API::Entities::Branch).to receive(:represent).with(anything, has_merged_branch_names_count(2))
+
+ get api(route, current_user), params: { per_page: 2 }
+ end
+
context 'when repository is disabled' do
include_context 'disabled repository'