Commit 58ed95bf authored by Ash McKenzie's avatar Ash McKenzie

Merge branch...

Merge branch '12161-follow-up-from-geo-remove-legacy-queries-from-geo-expireuploadsfinder' into 'master'

Refactor Geo::FileExpireService class

Closes #12161

See merge request gitlab-org/gitlab-ee!14285
parents ce2a9074 b5b9e514
......@@ -13,10 +13,10 @@ module Geo
scope :syncable, -> { with_files_stored_locally }
class << self
def for_model_with_type(model, type)
def for_model(model)
inner_join_file_registry
.where(model_id: model.id, model_type: model.class.name)
.merge(Geo::FileRegistry.with_file_type(type))
.merge(Geo::FileRegistry.uploads)
end
def inner_join_file_registry
......
......@@ -8,7 +8,7 @@ class Geo::FileRegistry < Geo::BaseRegistry
scope :fresh, -> { order(created_at: :desc) }
scope :lfs_objects, -> { where(file_type: :lfs) }
scope :never, -> { where(success: false, retry_count: nil) }
scope :with_file_type, ->(type) { where(file_type: type) }
scope :uploads, -> { where(file_type: Geo::FileService::UPLOAD_OBJECT_TYPE) }
self.inheritance_column = 'file_type'
......
......@@ -9,6 +9,7 @@ module Geo
DEFAULT_OBJECT_TYPES = %i[attachment avatar file import_export namespace_file personal_file favicon].freeze
DEFAULT_SERVICE_TYPE = :file
UPLOAD_OBJECT_TYPE = :file
def initialize(object_type, object_db_id)
@object_type = object_type.to_sym
......
......@@ -5,7 +5,6 @@ module Geo
include ::Gitlab::Geo::LogHelpers
BATCH_SIZE = 500
UPLOAD_TYPE = 'file'
attr_reader :project, :old_full_path
......@@ -26,7 +25,7 @@ module Geo
def execute
return unless Gitlab::Geo.secondary?
uploads = Geo::Fdw::Upload.for_model_with_type(project, UPLOAD_TYPE)
uploads = Geo::Fdw::Upload.for_model(project)
log_info("Expiring replicated attachments after project rename", count: uploads.count)
schedule_file_removal(uploads)
......@@ -61,7 +60,6 @@ module Geo
def mark_for_resync!
Gitlab::Geo::Fdw::UploadRegistryQueryBuilder.new
.for_model(project)
.with_type(UPLOAD_TYPE)
.delete_all
end
......
......@@ -5,9 +5,7 @@
#
# Basic usage:
#
# Gitlab::Geo::Fdw::UploadRegistryQueryBuilder
# .new
# .for_project_with_type(project, 'file')
# Gitlab::Geo::Fdw::UploadRegistryQueryBuilder.new.for_model(project)
#
module Gitlab
module Geo
......@@ -18,6 +16,7 @@ module Gitlab
reflect(
query
.joins(fdw_inner_join_uploads)
.merge(::Geo::FileRegistry.uploads)
.where(
fdw_upload_table[:model_id].eq(model.id)
.and(fdw_upload_table[:model_type].eq(model.class.name))
......@@ -26,10 +25,6 @@ module Gitlab
end
# rubocop:enable CodeReuse/ActiveRecord
def with_type(type)
reflect(query.merge(::Geo::FileRegistry.with_file_type(type)))
end
private
def base
......
......@@ -12,14 +12,8 @@ describe Gitlab::Geo::Fdw::UploadRegistryQueryBuilder, :geo, :geo_fdw do
let!(:file_registry_3) { create(:geo_file_registry, file_id: upload_3.id) }
describe '#for_model' do
it 'returns registries that upload belong to the model' do
expect(subject.for_model(project)).to match_ids(file_registry_1, file_registry_2)
end
end
describe '#with_type' do
it 'returns registries filtered by file_type' do
expect(subject.with_type('file')).to match_ids(file_registry_1, file_registry_3)
it 'returns registries for uploads that belong to the model' do
expect(subject.for_model(project)).to match_ids(file_registry_1)
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