Improve performance RegistryBackfillService with bulk insert

parent b617c71f
......@@ -15,12 +15,13 @@ class Geo::BaseRegistry < Geo::TrackingBase
where.not(self::MODEL_FOREIGN_KEY => ids)
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)
ids.map do |id|
registry = create(self::MODEL_FOREIGN_KEY => id)
registry.id
end.compact
inserts = ids.map do |id|
{ self::MODEL_FOREIGN_KEY => id, created_at: Time.zone.now }
end
ActiveRecord::InsertAll
.new(self, inserts, on_duplicate: :skip, returning: [:id])
.execute
end
end
......@@ -28,13 +28,15 @@ class Geo::UploadRegistry < Geo::BaseRegistry
false
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)
attrs.map do |file_id, file_type|
registry = create(file_id: file_id, file_type: file_type)
registry.id
end.compact
inserts = attrs.map do |file_id, file_type|
{ file_id: file_id, file_type: file_type, created_at: Time.zone.now }
end
ActiveRecord::InsertAll
.new(self, inserts, on_duplicate: :skip, returning: [:id])
.execute
.pluck('id')
end
def self.with_search(query)
......
......@@ -99,8 +99,8 @@ module Geo
registry_class: registry_class.name,
start: range.first,
finish: range.last,
created: created.size,
failed_to_create: untracked.size - created.size
created: created.length,
failed_to_create: untracked.length - created.length
}
)
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