summaryrefslogtreecommitdiff
path: root/app/models/project.rb
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/models/project.rb
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/models/project.rb')
-rw-r--r--app/models/project.rb35
1 files changed, 17 insertions, 18 deletions
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