Improve performance RegistryBackfillService with bulk insert

parent b617c71f
...@@ -15,12 +15,13 @@ class Geo::BaseRegistry < Geo::TrackingBase ...@@ -15,12 +15,13 @@ class Geo::BaseRegistry < Geo::TrackingBase
where.not(self::MODEL_FOREIGN_KEY => ids) where.not(self::MODEL_FOREIGN_KEY => ids)
end end
# TODO: Investigate replacing this with bulk insert (there was an obstacle).
# https://gitlab.com/gitlab-org/gitlab/issues/197310
def self.insert_for_model_ids(ids) def self.insert_for_model_ids(ids)
ids.map do |id| inserts = ids.map do |id|
registry = create(self::MODEL_FOREIGN_KEY => id) { self::MODEL_FOREIGN_KEY => id, created_at: Time.zone.now }
registry.id end
end.compact
ActiveRecord::InsertAll
.new(self, inserts, on_duplicate: :skip, returning: [:id])
.execute
end end
end end
...@@ -28,13 +28,15 @@ class Geo::UploadRegistry < Geo::BaseRegistry ...@@ -28,13 +28,15 @@ class Geo::UploadRegistry < Geo::BaseRegistry
false false
end end
# TODO: Investigate replacing this with bulk insert (there was an obstacle).
# https://gitlab.com/gitlab-org/gitlab/issues/197310
def self.insert_for_model_ids(attrs) def self.insert_for_model_ids(attrs)
attrs.map do |file_id, file_type| inserts = attrs.map do |file_id, file_type|
registry = create(file_id: file_id, file_type: file_type) { file_id: file_id, file_type: file_type, created_at: Time.zone.now }
registry.id end
end.compact
ActiveRecord::InsertAll
.new(self, inserts, on_duplicate: :skip, returning: [:id])
.execute
.pluck('id')
end end
def self.with_search(query) def self.with_search(query)
......
...@@ -99,8 +99,8 @@ module Geo ...@@ -99,8 +99,8 @@ module Geo
registry_class: registry_class.name, registry_class: registry_class.name,
start: range.first, start: range.first,
finish: range.last, finish: range.last,
created: created.size, created: created.length,
failed_to_create: untracked.size - created.size failed_to_create: untracked.length - created.length
} }
) )
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment