summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-11-17 16:27:38 +0000
committerDouwe Maan <douwe@gitlab.com>2017-11-17 16:27:38 +0000
commitc406824d319e5b1a073af7cf55c3f24bfa66e2a4 (patch)
tree46c4475af2343364794bf6a9f28211a9f8de28d7
parent371180a47d292957b73c6c9e1e662b6c99a62ee9 (diff)
parent5a335c4d955bbb74a50ca30ac45d30f6ef66774d (diff)
downloadgitlab-ce-c406824d319e5b1a073af7cf55c3f24bfa66e2a4.tar.gz
Merge branch 'bvl-fix-count-with-selects' into 'master'
Remove the selects when counting the last page Closes #40266 See merge request gitlab-org/gitlab-ce!15456
-rw-r--r--changelogs/unreleased/bvl-fix-count-with-selects.yml6
-rw-r--r--lib/gitlab/multi_collection_paginator.rb4
-rw-r--r--spec/controllers/groups/children_controller_spec.rb11
3 files changed, 20 insertions, 1 deletions
diff --git a/changelogs/unreleased/bvl-fix-count-with-selects.yml b/changelogs/unreleased/bvl-fix-count-with-selects.yml
new file mode 100644
index 00000000000..46a882de524
--- /dev/null
+++ b/changelogs/unreleased/bvl-fix-count-with-selects.yml
@@ -0,0 +1,6 @@
+---
+title: Fix crash when navigating to second page of the group dashbaord when there
+ are projects and groups on the first page
+merge_request: 15456
+author:
+type: fixed
diff --git a/lib/gitlab/multi_collection_paginator.rb b/lib/gitlab/multi_collection_paginator.rb
index eb3c9002710..c22d0a84860 100644
--- a/lib/gitlab/multi_collection_paginator.rb
+++ b/lib/gitlab/multi_collection_paginator.rb
@@ -55,7 +55,9 @@ module Gitlab
def first_collection_last_page_size
return @first_collection_last_page_size if defined?(@first_collection_last_page_size)
- @first_collection_last_page_size = paginated_first_collection(first_collection_page_count).count
+ @first_collection_last_page_size = paginated_first_collection(first_collection_page_count)
+ .except(:select)
+ .size
end
end
end
diff --git a/spec/controllers/groups/children_controller_spec.rb b/spec/controllers/groups/children_controller_spec.rb
index 4262d474e59..cb1b460fc0e 100644
--- a/spec/controllers/groups/children_controller_spec.rb
+++ b/spec/controllers/groups/children_controller_spec.rb
@@ -280,6 +280,17 @@ describe Groups::ChildrenController do
expect(assigns(:children)).to contain_exactly(other_subgroup, *next_page_projects.take(per_page - 1))
end
+
+ context 'with a mixed first page' do
+ let!(:first_page_subgroups) { [create(:group, :public, parent: group)] }
+ let!(:first_page_projects) { create_list(:project, per_page, :public, namespace: group) }
+
+ it 'correctly calculates the counts' do
+ get :index, group_id: group.to_param, sort: 'id_asc', page: 2, format: :json
+
+ expect(response).to have_gitlab_http_status(200)
+ end
+ end
end
end
end