Commit e529ce9f authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'mc_rocha-remove-extra-project-loads-350352' into 'master'

Remove extra projects loads on dast_profiles policy check

See merge request gitlab-org/gitlab!78312
parents 9cec3e8d 34efffe8
......@@ -6,16 +6,21 @@ class DastScannerProfilesFinder
end
def execute
relation = DastScannerProfile.all
relation = init_collection
relation = by_id(relation)
relation = by_project(relation)
by_name(relation)
relation = by_name(relation)
relation.with_project
end
private
attr_reader :params
def init_collection
DastScannerProfile.all
end
def by_id(relation)
return relation unless params[:ids]
......
......@@ -9,28 +9,25 @@ class DastSiteProfilesFinder
relation = DastSiteProfile.with_dast_site_and_validation
relation = by_id(relation)
relation = by_project(relation)
by_name(relation)
relation = by_name(relation)
relation.with_project
end
private
attr_reader :params
# rubocop: disable CodeReuse/ActiveRecord
def by_id(relation)
return relation if params[:id].nil?
relation.where(id: params[:id]).limit(1)
relation.id_in(params[:id]).limit(1)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_project(relation)
return relation if params[:project_id].nil?
relation.where(project_id: params[:project_id])
relation.with_project_id(params[:project_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def by_name(relation)
return relation unless params[:name]
......
......@@ -10,6 +10,7 @@ class DastScannerProfile < ApplicationRecord
scope :project_id_in, -> (project_ids) { where(project_id: project_ids) }
scope :with_name, -> (name) { where(name: name) }
scope :with_project, -> { includes(:project) }
enum scan_type: {
passive: 1,
......
......@@ -20,6 +20,8 @@ class DastSiteProfile < ApplicationRecord
scope :with_dast_site_and_validation, -> { includes(dast_site: :dast_site_validation) }
scope :with_name, -> (name) { where(name: name) }
scope :with_project_id, -> (project_id) { where(project_id: project_id) }
scope :with_project, -> { includes(:project) }
after_destroy :cleanup_dast_site
......
......@@ -226,8 +226,7 @@ RSpec.describe Ci::CreatePipelineService do
1 + # INSERT INTO "ci_builds"
1 + # INSERT INTO "ci_builds_metadata"
1 + # SELECT "taggings".* FROM "taggings"
1 + # SELECT "ci_pipelines"."id" FROM
1 # SELECT "projects".id
1 # SELECT "ci_pipelines"."id" FROM
end
def execute_service
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment