Commit c013812d authored by Gabriel Mazetto's avatar Gabriel Mazetto

Move unrelated code from Geo::FileService

Gitlab::Geo::FileReplication should hold logic that is shared among
multiple classes.
parent 3ca312d3
...@@ -49,7 +49,7 @@ module Geo ...@@ -49,7 +49,7 @@ module Geo
join_statement = join_statement =
arel_table arel_table
.join(file_registry_table, Arel::Nodes::OuterJoin) .join(file_registry_table, Arel::Nodes::OuterJoin)
.on(arel_table[:id].eq(file_registry_table[:file_id]).and(file_registry_table[:file_type].in(Geo::FileService::DEFAULT_OBJECT_TYPES))) .on(arel_table[:id].eq(file_registry_table[:file_id]).and(file_registry_table[:file_type].in(Gitlab::Geo::FileReplication::USER_UPLOADS_OBJECT_TYPES)))
joins(join_statement.join_sources) joins(join_statement.join_sources)
end end
......
...@@ -3,19 +3,19 @@ ...@@ -3,19 +3,19 @@
class Geo::FileRegistry < Geo::BaseRegistry class Geo::FileRegistry < Geo::BaseRegistry
include Geo::Syncable include Geo::Syncable
scope :attachments, -> { where(file_type: Geo::FileService::DEFAULT_OBJECT_TYPES) } scope :attachments, -> { where(file_type: Gitlab::Geo::FileReplication::USER_UPLOADS_OBJECT_TYPES) }
scope :failed, -> { where(success: false).where.not(retry_count: nil) } scope :failed, -> { where(success: false).where.not(retry_count: nil) }
scope :fresh, -> { order(created_at: :desc) } scope :fresh, -> { order(created_at: :desc) }
scope :lfs_objects, -> { where(file_type: :lfs) } scope :lfs_objects, -> { where(file_type: :lfs) }
scope :never, -> { where(success: false, retry_count: nil) } scope :never, -> { where(success: false, retry_count: nil) }
scope :uploads, -> { where(file_type: Geo::FileService::UPLOAD_OBJECT_TYPE) } scope :uploads, -> { where(file_type: Gitlab::Geo::FileReplication::UPLOAD_OBJECT_TYPE) }
self.inheritance_column = 'file_type' self.inheritance_column = 'file_type'
def self.find_sti_class(file_type) def self.find_sti_class(file_type)
if file_type == 'lfs' if file_type == 'lfs'
Geo::LfsObjectRegistry Geo::LfsObjectRegistry
elsif Geo::FileService::DEFAULT_OBJECT_TYPES.include?(file_type.to_sym) elsif Gitlab::Geo::FileReplication.object_type_from_user_uploads?(file_type)
Geo::UploadRegistry Geo::UploadRegistry
end end
end end
......
...@@ -10,7 +10,7 @@ class Geo::UploadRegistry < Geo::FileRegistry ...@@ -10,7 +10,7 @@ class Geo::UploadRegistry < Geo::FileRegistry
def self.type_condition(table = arel_table) def self.type_condition(table = arel_table)
sti_column = arel_attribute(inheritance_column, table) sti_column = arel_attribute(inheritance_column, table)
sti_names = Geo::FileService::DEFAULT_OBJECT_TYPES sti_names = Gitlab::Geo::FileReplication::USER_UPLOADS_OBJECT_TYPES
sti_column.in(sti_names) sti_column.in(sti_names)
end end
......
...@@ -78,7 +78,7 @@ module Geo ...@@ -78,7 +78,7 @@ module Geo
LfsObject.find(object_db_id).file LfsObject.find(object_db_id).file
when :job_artifact when :job_artifact
Ci::JobArtifact.find(object_db_id).file Ci::JobArtifact.find(object_db_id).file
when *Geo::FileService::DEFAULT_OBJECT_TYPES when *Gitlab::Geo::FileReplication::USER_UPLOADS_OBJECT_TYPES
Upload.find(object_db_id).build_uploader Upload.find(object_db_id).build_uploader
else else
raise NameError, "Unrecognized type: #{object_type}" raise NameError, "Unrecognized type: #{object_type}"
......
...@@ -7,9 +7,7 @@ module Geo ...@@ -7,9 +7,7 @@ module Geo
attr_reader :object_type, :object_db_id attr_reader :object_type, :object_db_id
DEFAULT_OBJECT_TYPES = %i[attachment avatar file import_export namespace_file personal_file favicon].freeze DEFAULT_KLASS_NAME = 'File'.freeze
DEFAULT_SERVICE_TYPE = :file
UPLOAD_OBJECT_TYPE = :file
def initialize(object_type, object_db_id) def initialize(object_type, object_db_id)
@object_type = object_type.to_sym @object_type = object_type.to_sym
...@@ -22,8 +20,8 @@ module Geo ...@@ -22,8 +20,8 @@ module Geo
private private
def upload? def upload_object?
DEFAULT_OBJECT_TYPES.include?(object_type) Gitlab::Geo::FileReplication.object_type_from_user_uploads?(object_type)
end end
def job_artifact? def job_artifact?
...@@ -31,14 +29,9 @@ module Geo ...@@ -31,14 +29,9 @@ module Geo
end end
def service_klass_name def service_klass_name
klass_name = return DEFAULT_KLASS_NAME if upload_object?
if upload?
DEFAULT_SERVICE_TYPE object_type.to_s.camelize
else
object_type
end
klass_name.to_s.camelize
end end
def base_log_data(message) def base_log_data(message)
......
...@@ -66,7 +66,7 @@ module Geo ...@@ -66,7 +66,7 @@ module Geo
def job_finders def job_finders
@job_finders ||= [ @job_finders ||= [
Geo::FileDownloadDispatchWorker::AttachmentJobFinder.new(scheduled_file_ids(Geo::FileService::DEFAULT_OBJECT_TYPES)), Geo::FileDownloadDispatchWorker::AttachmentJobFinder.new(scheduled_file_ids(Gitlab::Geo::FileReplication::USER_UPLOADS_OBJECT_TYPES)),
Geo::FileDownloadDispatchWorker::LfsObjectJobFinder.new(scheduled_file_ids(:lfs)), Geo::FileDownloadDispatchWorker::LfsObjectJobFinder.new(scheduled_file_ids(:lfs)),
Geo::FileDownloadDispatchWorker::JobArtifactJobFinder.new(scheduled_file_ids(:job_artifact)) Geo::FileDownloadDispatchWorker::JobArtifactJobFinder.new(scheduled_file_ids(:job_artifact))
] ]
......
...@@ -58,7 +58,7 @@ module Geo ...@@ -58,7 +58,7 @@ module Geo
def find_migrated_local_attachments_ids(batch_size:) def find_migrated_local_attachments_ids(batch_size:)
return [] unless attachments_object_store_enabled? return [] unless attachments_object_store_enabled?
attachments_finder.find_migrated_local(batch_size: batch_size, except_file_ids: scheduled_file_ids(Geo::FileService::DEFAULT_OBJECT_TYPES)) attachments_finder.find_migrated_local(batch_size: batch_size, except_file_ids: scheduled_file_ids(Gitlab::Geo::FileReplication::USER_UPLOADS_OBJECT_TYPES))
.pluck(:uploader, :id) .pluck(:uploader, :id)
.map { |uploader, id| [uploader.sub(/Uploader\z/, '').underscore, id] } .map { |uploader, id| [uploader.sub(/Uploader\z/, '').underscore, id] }
end end
......
# frozen_string_literal: true
module Gitlab
module Geo
module FileReplication
USER_UPLOADS_OBJECT_TYPES = %i[attachment avatar file import_export namespace_file personal_file favicon].freeze
UPLOAD_OBJECT_TYPE = :file
def object_type_from_user_uploads?(object_type)
USER_UPLOADS_OBJECT_TYPES.include?(object_type.to_sym)
end
end
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