summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-11-16 16:27:54 +0000
committerDouwe Maan <douwe@gitlab.com>2016-11-16 16:27:54 +0000
commit4e63411daae631c5e6221fe8ee674f55239e713b (patch)
tree3eca7c861bc047ec72f748fbed7a64056432e480 /lib/api/helpers.rb
parent891465ba8cd57bb928e82ba070f2d7efb63f6282 (diff)
parentef3be00a0297dfa31002616df6ee49a0e2132cb7 (diff)
downloadgitlab-ce-4e63411daae631c5e6221fe8ee674f55239e713b.tar.gz
Merge branch 'adam-build-missing-services-when-necessary' into 'master'
Defer saving project services to the database if there are no user changes ## What does this MR do? It defers saving project services to the database as long as it is possible. It creates a project service when creating a project only if this project service has an active template. After that project services are saved on the first edit. ## Are there points in the code the reviewer needs to double check? - tests that used `build_missing_services` before the change - number of queries executed ## Why was this MR needed? Motivation in #22281 ## Does this MR meet the acceptance criteria? - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - Tests - [x] Added for this feature/bug - [x] All builds are passing - [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html) - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if it does - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) ## What are the relevant issue numbers? Fixes #22281 See merge request !6958
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb17
1 files changed, 1 insertions, 16 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 6998b6dc039..84cc9200d1b 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -86,25 +86,10 @@ module API
end
def project_service
- @project_service ||= begin
- underscored_service = params[:service_slug].underscore
-
- if Service.available_services_names.include?(underscored_service)
- user_project.build_missing_services
-
- service_method = "#{underscored_service}_service"
-
- send_service(service_method)
- end
- end
-
+ @project_service ||= user_project.find_or_initialize_service(params[:service_slug].underscore)
@project_service || not_found!("Service")
end
- def send_service(service_method)
- user_project.send(service_method)
- end
-
def service_attributes
@service_attributes ||= project_service.fields.inject([]) do |arr, hash|
arr << hash[:name].to_sym