diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/concerns/integrations_actions.rb | 2 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 10 | ||||
-rw-r--r-- | app/models/project.rb | 5 | ||||
-rw-r--r-- | app/services/admin/propagate_integration_service.rb | 28 | ||||
-rw-r--r-- | app/services/projects/propagate_service_template.rb | 32 |
5 files changed, 43 insertions, 34 deletions
diff --git a/app/controllers/concerns/integrations_actions.rb b/app/controllers/concerns/integrations_actions.rb index b3ad89f3227..b06b7b212e9 100644 --- a/app/controllers/concerns/integrations_actions.rb +++ b/app/controllers/concerns/integrations_actions.rb @@ -16,7 +16,7 @@ module IntegrationsActions def update saved = integration.update(service_params[:service]) - overwrite = ActiveRecord::Type::Boolean.new.cast(params[:overwrite]) + overwrite = Gitlab::Utils.to_boolean(params[:overwrite]) respond_to do |format| format.html do diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 2cfae7c272b..ff6d9350a5c 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -5,6 +5,10 @@ class SearchController < ApplicationController include SearchHelper include RendersCommits + SCOPE_PRELOAD_METHOD = { + projects: :with_web_entity_associations + }.freeze + around_action :allow_gitaly_ref_name_caching skip_before_action :authenticate_user! @@ -28,7 +32,7 @@ class SearchController < ApplicationController @scope = search_service.scope @show_snippets = search_service.show_snippets? @search_results = search_service.search_results - @search_objects = search_service.search_objects + @search_objects = search_service.search_objects(preload_method) render_commits if @scope == 'commits' eager_load_user_status if @scope == 'users' @@ -64,6 +68,10 @@ class SearchController < ApplicationController private + def preload_method + SCOPE_PRELOAD_METHOD[@scope.to_sym] + end + def search_term_valid? unless search_service.valid_query_length? flash[:alert] = t('errors.messages.search_chars_too_long', count: SearchService::SEARCH_CHAR_LIMIT) diff --git a/app/models/project.rb b/app/models/project.rb index a21085c73c8..0929757f8d4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -509,6 +509,7 @@ class Project < ApplicationRecord left_outer_joins(:pages_metadatum) .where(project_pages_metadata: { project_id: nil }) end + scope :with_api_entity_associations, -> { preload(:project_feature, :route, :tags, group: :ip_restrictions, namespace: [:route, :owner]) @@ -528,6 +529,10 @@ class Project < ApplicationRecord # Used by Projects::CleanupService to hold a map of rewritten object IDs mount_uploader :bfg_object_map, AttachmentUploader + def self.with_web_entity_associations + preload(:project_feature, :route, :creator, :group, namespace: [:route, :owner]) + end + def self.eager_load_namespace_and_owner includes(namespace: :owner) end diff --git a/app/services/admin/propagate_integration_service.rb b/app/services/admin/propagate_integration_service.rb index 0a3c61816f8..084b103ee3b 100644 --- a/app/services/admin/propagate_integration_service.rb +++ b/app/services/admin/propagate_integration_service.rb @@ -114,23 +114,21 @@ module Admin integration.type == 'ExternalWikiService' end + # rubocop: disable CodeReuse/ActiveRecord def project_ids_without_integration - Project.connection.select_values( - <<-SQL - SELECT id - FROM projects - WHERE NOT EXISTS ( - SELECT true - FROM services - WHERE services.project_id = projects.id - AND services.type = #{ActiveRecord::Base.connection.quote(integration.type)} - ) - AND projects.pending_delete = false - AND projects.archived = false - LIMIT #{BATCH_SIZE} - SQL - ) + services = Service + .select('1') + .where('services.project_id = projects.id') + .where(type: integration.type) + + Project + .where('NOT EXISTS (?)', services) + .where(pending_delete: false) + .where(archived: false) + .limit(BATCH_SIZE) + .pluck(:id) end + # rubocop: enable CodeReuse/ActiveRecord def service_hash @service_hash ||= integration.to_service_hash diff --git a/app/services/projects/propagate_service_template.rb b/app/services/projects/propagate_service_template.rb index ecca9715940..4adcda042d1 100644 --- a/app/services/projects/propagate_service_template.rb +++ b/app/services/projects/propagate_service_template.rb @@ -26,7 +26,7 @@ module Projects def propagate_projects_with_template loop do - batch = Project.uncached { project_ids_batch } + batch = Project.uncached { project_ids_without_integration } bulk_create_from_template(batch) unless batch.empty? @@ -50,23 +50,21 @@ module Projects end end - def project_ids_batch - Project.connection.select_values( - <<-SQL - SELECT id - FROM projects - WHERE NOT EXISTS ( - SELECT true - FROM services - WHERE services.project_id = projects.id - AND services.type = #{ActiveRecord::Base.connection.quote(template.type)} - ) - AND projects.pending_delete = false - AND projects.archived = false - LIMIT #{BATCH_SIZE} - SQL - ) + # rubocop: disable CodeReuse/ActiveRecord + def project_ids_without_integration + services = Service + .select('1') + .where('services.project_id = projects.id') + .where(type: template.type) + + Project + .where('NOT EXISTS (?)', services) + .where(pending_delete: false) + .where(archived: false) + .limit(BATCH_SIZE) + .pluck(:id) end + # rubocop: enable CodeReuse/ActiveRecord def bulk_insert(klass, columns, values_array) items_to_insert = values_array.map { |array| Hash[columns.zip(array)] } |