From 5b6d5301d9589b694fea0820a2b6cf165642669b Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 5 Nov 2018 15:37:21 -0800 Subject: Paginate Bitbucket Server importer projects To prevent delays in loading the page and reduce memory usage, limit the number of projects shown at 25 per page. Part of https://gitlab.com/gitlab-org/gitlab-ce/issues/50021 --- .../import/bitbucket_server_controller.rb | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'app/controllers/import') diff --git a/app/controllers/import/bitbucket_server_controller.rb b/app/controllers/import/bitbucket_server_controller.rb index fdd1078cdf7..575c40d5f6f 100644 --- a/app/controllers/import/bitbucket_server_controller.rb +++ b/app/controllers/import/bitbucket_server_controller.rb @@ -54,14 +54,14 @@ class Import::BitbucketServerController < Import::BaseController # rubocop: disable CodeReuse/ActiveRecord def status - repos = bitbucket_client.repos + @collection = bitbucket_client.repos(page_offset: page_offset, limit: limit_per_page) + @repos, @incompatible_repos = @collection.partition { |repo| repo.valid? } - @repos, @incompatible_repos = repos.partition { |repo| repo.valid? } - - @already_added_projects = find_already_added_projects('bitbucket_server') + # Use the import URL to filter beyond what BaseService#find_already_added_projects + @already_added_projects = filter_added_projects('bitbucket_server', @repos.map(&:browse_url)) already_added_projects_names = @already_added_projects.pluck(:import_source) - @repos.to_a.reject! { |repo| already_added_projects_names.include?(repo.browse_url) } + @repos.reject! { |repo| already_added_projects_names.include?(repo.browse_url) } rescue BitbucketServer::Connection::ConnectionError, BitbucketServer::Client::ServerError => e flash[:alert] = "Unable to connect to server: #{e}" clear_session_data @@ -75,6 +75,12 @@ class Import::BitbucketServerController < Import::BaseController private + # rubocop: disable CodeReuse/ActiveRecord + def filter_added_projects(import_type, import_sources) + current_user.created_projects.where(import_type: import_type, import_source: import_sources).includes(:import_state) + end + # rubocop: enable CodeReuse/ActiveRecord + def bitbucket_client @bitbucket_client ||= BitbucketServer::Client.new(credentials) end @@ -130,4 +136,12 @@ class Import::BitbucketServerController < Import::BaseController password: session[personal_access_token_key] } end + + def page_offset + [0, params[:page].to_i].max + end + + def limit_per_page + BitbucketServer::Paginator::PAGE_LENGTH + end end -- cgit v1.2.1