summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-10-05 18:51:04 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-10-05 18:51:04 +0000
commit81e435c4a570af757f477e296a2fb3be8e073b8b (patch)
tree89b3e333c17ca451f327fbea08b88e59a9854f8d /app
parentb1d8cd2eec6759ad2db7e119ed220fa00196b800 (diff)
parentcc339aa60877214820f9445336b5cf7766601176 (diff)
downloadgitlab-ce-81e435c4a570af757f477e296a2fb3be8e073b8b.tar.gz
Merge branch '43109-ci_environments_status-json-executes-more-than-100-queries' into 'master'
Resolve "Controller Projects::MergeRequestsController#ci_environments_status.json executes more than 100 SQL queries" Closes #43109 See merge request gitlab-org/gitlab-ce!21996
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/merge_requests_controller.rb4
-rw-r--r--app/models/project.rb35
2 files changed, 19 insertions, 20 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index d691744d72a..6a5da9b8292 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -207,7 +207,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
environments =
begin
@merge_request.environments_for(current_user).map do |environment|
- project = environment.project
+ project = environment.project
deployment = environment.first_deployment_for(@merge_request.diff_head_sha)
stop_url =
@@ -217,7 +217,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
metrics_url =
if can?(current_user, :read_environment, environment) && environment.has_metrics?
- metrics_project_environment_deployment_path(environment.project, environment, deployment)
+ metrics_project_environment_deployment_path(project, environment, deployment)
end
metrics_monitoring_url =
diff --git a/app/models/project.rb b/app/models/project.rb
index dc2732cc6c2..3fa47c1cda3 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1082,26 +1082,10 @@ class Project < ActiveRecord::Base
end
def find_or_initialize_services(exceptions: [])
- services_templates = Service.where(template: true)
-
available_services_names = Service.available_services_names - exceptions
available_services = available_services_names.map do |service_name|
- service = find_service(services, service_name)
-
- if service
- service
- else
- # We should check if template for the service exists
- template = find_service(services_templates, service_name)
-
- if template.nil?
- # If no template, we should create an instance. Ex `build_gitlab_ci_service`
- public_send("build_#{service_name}_service") # rubocop:disable GitlabSecurity/PublicSend
- else
- Service.build_from_template(id, template)
- end
- end
+ find_or_initialize_service(service_name)
end
available_services.reject do |service|
@@ -1114,7 +1098,18 @@ class Project < ActiveRecord::Base
end
def find_or_initialize_service(name)
- find_or_initialize_services.find { |service| service.to_param == name }
+ service = find_service(services, name)
+ return service if service
+
+ # We should check if template for the service exists
+ template = find_service(services_templates, name)
+
+ if template
+ Service.build_from_template(id, template)
+ else
+ # If no template, we should create an instance. Ex `build_gitlab_ci_service`
+ public_send("build_#{name}_service") # rubocop:disable GitlabSecurity/PublicSend
+ end
end
# rubocop: disable CodeReuse/ServiceClass
@@ -2277,4 +2272,8 @@ class Project < ActiveRecord::Base
check_access.call
end
end
+
+ def services_templates
+ @services_templates ||= Service.where(template: true)
+ end
end