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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-27 21:07:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-27 21:07:48 +0300
commite20baee820ea2c76ee16980a98e8080f255d9035 (patch)
tree6e13a73bee42b7ef310850d03982faebea17a0b1 /app/models
parent71c5863d7b1ca9836a7d7703f35750cd726a9846 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/bulk_insert_safe.rb4
-rw-r--r--app/models/service.rb20
2 files changed, 18 insertions, 6 deletions
diff --git a/app/models/concerns/bulk_insert_safe.rb b/app/models/concerns/bulk_insert_safe.rb
index f1a2d566e97..e09f44e68dc 100644
--- a/app/models/concerns/bulk_insert_safe.rb
+++ b/app/models/concerns/bulk_insert_safe.rb
@@ -160,9 +160,7 @@ module BulkInsertSafe
attributes = {}
column_names.each do |name|
- value = item.read_attribute(name)
- value = item.type_for_attribute(name).serialize(value) # rubocop:disable Cop/ActiveRecordSerialize
- attributes[name] = value
+ attributes[name] = item.read_attribute(name)
end
_bulk_insert_reject_primary_key!(attributes, item.class.primary_key)
diff --git a/app/models/service.rb b/app/models/service.rb
index 138da0c546e..e4ae68cdaa7 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -47,6 +47,7 @@ class Service < ApplicationRecord
scope :without_defaults, -> { where(default: false) }
scope :by_type, -> (type) { where(type: type) }
scope :templates, -> { where(template: true, type: available_services_types) }
+ scope :instances, -> { where(instance: true, type: available_services_types) }
scope :push_hooks, -> { where(push_events: true, active: true) }
scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) }
@@ -260,17 +261,16 @@ class Service < ApplicationRecord
self.category == :issue_tracker
end
- # Find all service templates; if some of them do not exist, create them
- # within a transaction to perform the lowest possible SQL queries.
def self.find_or_create_templates
create_nonexistent_templates
templates
end
private_class_method def self.create_nonexistent_templates
- nonexistent_services = available_services_types - templates.map(&:type)
+ nonexistent_services = list_nonexistent_services_for(templates)
return if nonexistent_services.empty?
+ # Create within a transaction to perform the lowest possible SQL queries.
transaction do
nonexistent_services.each do |service_type|
service_type.constantize.create(template: true)
@@ -278,6 +278,20 @@ class Service < ApplicationRecord
end
end
+ def self.find_or_initialize_instances
+ instances + build_nonexistent_instances
+ end
+
+ private_class_method def self.build_nonexistent_instances
+ list_nonexistent_services_for(instances).map do |service_type|
+ service_type.constantize.new
+ end
+ end
+
+ private_class_method def self.list_nonexistent_services_for(scope)
+ available_services_types - scope.map(&:type)
+ end
+
def self.available_services_names
service_names = %w[
alerts