Removed pagination from AutocompleteUsersFinder

The frontend code doesn't use this so there's no practical point in
supporting this. We also hardcode the limit to 20 so users can no longer
request their own limit, which could overload the database (depending on
any upper bounds perhaps enforced by Kaminari).
This commit is contained in:
Yorick Peterse 2018-02-15 19:33:35 +01:00
parent dd52915dc6
commit d2e43fbde6
No known key found for this signature in database
GPG key ID: EDD30D2BEB691AC9
4 changed files with 14 additions and 11 deletions

View file

@ -14,7 +14,6 @@ export default class DropdownUser extends FilteredSearchDropdown {
endpoint: `${gon.relative_url_root || ''}/autocomplete/users.json`,
searchKey: 'search',
params: {
per_page: 20,
active: true,
group_id: this.getGroupId(),
project_id: this.getProjectId(),

View file

@ -39,7 +39,6 @@ function UsersSelect(currentUser, els, options = {}) {
options.showCurrentUser = $dropdown.data('currentUser');
options.todoFilter = $dropdown.data('todoFilter');
options.todoStateFilter = $dropdown.data('todoStateFilter');
options.perPage = $dropdown.data('perPage');
showNullUser = $dropdown.data('nullUser');
defaultNullUser = $dropdown.data('nullUserDefault');
showMenuAbove = $dropdown.data('showMenuAbove');
@ -669,7 +668,6 @@ UsersSelect.prototype.users = function(query, options, callback) {
const url = this.buildUrl(this.usersPath);
const params = {
search: query,
per_page: options.perPage || 20,
active: true,
project_id: options.projectId || null,
group_id: options.groupId || null,

View file

@ -1,6 +1,12 @@
class AutocompleteUsersFinder
# The number of users to display in the results is hardcoded to 20, and
# pagination is not supported. This ensures that performance remains
# consistent and removes the need for implementing keyset pagination to ensure
# good performance.
LIMIT = 20
attr_reader :current_user, :project, :group, :search, :skip_users,
:page, :per_page, :author_id, :params
:author_id, :params
def initialize(params:, current_user:, project:, group:)
@current_user = current_user
@ -8,8 +14,6 @@ class AutocompleteUsersFinder
@group = group
@search = params[:search]
@skip_users = params[:skip_users]
@page = params[:page]
@per_page = params[:per_page]
@author_id = params[:author_id]
@params = params
end
@ -20,7 +24,7 @@ class AutocompleteUsersFinder
items = items.reorder(:name)
items = items.search(search) if search.present?
items = items.where.not(id: skip_users) if skip_users.present?
items = items.page(page).per(per_page)
items = items.limit(LIMIT)
if params[:todo_filter].present? && current_user
items = items.todo_authors(current_user.id, params[:todo_state_filter])

View file

@ -109,15 +109,17 @@ describe AutocompleteController do
end
context 'limited users per page' do
let(:per_page) { 2 }
before do
25.times do
create(:user)
end
sign_in(user)
get(:users, per_page: per_page)
get(:users)
end
it { expect(json_response).to be_kind_of(Array) }
it { expect(json_response.size).to eq(per_page) }
it { expect(json_response.size).to eq(20) }
end
context 'unauthenticated user' do