Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-10-13 09:08:51 +0300
committerPaco Guzman <pacoguzmanp@gmail.com>2016-10-18 09:14:51 +0300
commitdb88fc287764d052cc25c7ef7f0fbcbd4c3a8566 (patch)
tree40d624e33a5ee082153af4a6683abd683a7a7860
parent4e6af0c3fa335d138343dce3e0216303a9b1cd79 (diff)
Reduce DB queries building missing services
-rw-r--r--app/models/project.rb4
-rw-r--r--app/models/service.rb12
2 files changed, 10 insertions, 6 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index db3088677d8..15341128d33 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -706,7 +706,7 @@ class Project < ActiveRecord::Base
end
def build_missing_services
- services_templates = Service.where(template: true)
+ services_templates = Service.where(template: true).to_a
Service.available_services_names.each do |service_name|
service = find_service(services, service_name)
@@ -720,7 +720,7 @@ class Project < ActiveRecord::Base
# If no template, we should create an instance. Ex `create_gitlab_ci_service`
self.send :"create_#{service_name}_service"
else
- Service.create_from_template(self.id, template)
+ Service.create_from_template(self, template)
end
end
end
diff --git a/app/models/service.rb b/app/models/service.rb
index 66c804f2b06..5b5847a921e 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -195,6 +195,10 @@ class Service < ActiveRecord::Base
self.category == :issue_tracker
end
+ def external_wiki?
+ self.type == "ExternalWikiService"
+ end
+
def self.available_services_names
%w(
asana
@@ -221,23 +225,23 @@ class Service < ActiveRecord::Base
)
end
- def self.create_from_template(project_id, template)
+ def self.create_from_template(project, template)
service = template.dup
service.template = false
- service.project_id = project_id
+ service.project = project
service if service.save
end
private
def cache_project_has_external_issue_tracker
- if project && !project.destroyed?
+ if issue_tracker? && project && !project.destroyed?
project.cache_has_external_issue_tracker
end
end
def cache_project_has_external_wiki
- if project && !project.destroyed?
+ if external_wiki? && project && !project.destroyed?
project.cache_has_external_wiki
end
end