Commit 9ab20185 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'mk/rename-methods' into 'master'

Geo: Small refactor renaming some methods

See merge request gitlab-org/gitlab!19712
parents 037dd58e 84f9311a
...@@ -47,7 +47,7 @@ module Geo ...@@ -47,7 +47,7 @@ module Geo
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_file_ids: []) def find_unsynced(batch_size:, except_file_ids: [])
attachments attachments
.missing_file_registry .missing_registry
.id_not_in(except_file_ids) .id_not_in(except_file_ids)
.limit(batch_size) .limit(batch_size)
end end
...@@ -56,7 +56,7 @@ module Geo ...@@ -56,7 +56,7 @@ module Geo
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_file_ids: []) def find_migrated_local(batch_size:, except_file_ids: [])
all_attachments all_attachments
.inner_join_file_registry .inner_join_registry
.with_files_stored_remotely .with_files_stored_remotely
.id_not_in(except_file_ids) .id_not_in(except_file_ids)
.limit(batch_size) .limit(batch_size)
...@@ -95,7 +95,7 @@ module Geo ...@@ -95,7 +95,7 @@ module Geo
end end
def registries_for_attachments def registries_for_attachments
attachments.inner_join_file_registry attachments.inner_join_registry
end end
end end
end end
...@@ -41,7 +41,7 @@ module Geo ...@@ -41,7 +41,7 @@ module Geo
# rubocop:disable CodeReuse/ActiveRecord # rubocop:disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_ids: []) def find_unsynced(batch_size:, except_ids: [])
lfs_objects lfs_objects
.missing_file_registry .missing_registry
.id_not_in(except_ids) .id_not_in(except_ids)
.limit(batch_size) .limit(batch_size)
end end
...@@ -50,7 +50,7 @@ module Geo ...@@ -50,7 +50,7 @@ module Geo
# rubocop:disable CodeReuse/ActiveRecord # rubocop:disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_ids: []) def find_migrated_local(batch_size:, except_ids: [])
all_lfs_objects all_lfs_objects
.inner_join_lfs_object_registry .inner_join_registry
.with_files_stored_remotely .with_files_stored_remotely
.id_not_in(except_ids) .id_not_in(except_ids)
.limit(batch_size) .limit(batch_size)
......
...@@ -17,45 +17,45 @@ module Geo ...@@ -17,45 +17,45 @@ module Geo
class << self class << self
def failed def failed
inner_join_lfs_object_registry inner_join_registry
.merge(Geo::LfsObjectRegistry.failed) .merge(Geo::LfsObjectRegistry.failed)
end end
def inner_join_lfs_object_registry def inner_join_registry
join_statement = join_statement =
arel_table arel_table
.join(lfs_object_registry_table, Arel::Nodes::InnerJoin) .join(registry_table, Arel::Nodes::InnerJoin)
.on(arel_table[:id].eq(lfs_object_registry_table[:lfs_object_id])) .on(arel_table[:id].eq(registry_table[:lfs_object_id]))
joins(join_statement.join_sources) joins(join_statement.join_sources)
end end
def missing_file_registry def missing_registry
left_outer_join_lfs_object_registry left_outer_join_registry
.where(lfs_object_registry_table[:id].eq(nil)) .where(registry_table[:id].eq(nil))
end end
def missing_on_primary def missing_on_primary
inner_join_lfs_object_registry inner_join_registry
.merge(Geo::LfsObjectRegistry.synced.missing_on_primary) .merge(Geo::LfsObjectRegistry.synced.missing_on_primary)
end end
def synced def synced
inner_join_lfs_object_registry inner_join_registry
.merge(Geo::LfsObjectRegistry.synced) .merge(Geo::LfsObjectRegistry.synced)
end end
private private
def lfs_object_registry_table def registry_table
Geo::LfsObjectRegistry.arel_table Geo::LfsObjectRegistry.arel_table
end end
def left_outer_join_lfs_object_registry def left_outer_join_registry
join_statement = join_statement =
arel_table arel_table
.join(lfs_object_registry_table, Arel::Nodes::OuterJoin) .join(registry_table, Arel::Nodes::OuterJoin)
.on(arel_table[:id].eq(lfs_object_registry_table[:lfs_object_id])) .on(arel_table[:id].eq(registry_table[:lfs_object_id]))
joins(join_statement.join_sources) joins(join_statement.join_sources)
end end
......
...@@ -15,17 +15,17 @@ module Geo ...@@ -15,17 +15,17 @@ module Geo
class << self class << self
def for_model(model) def for_model(model)
inner_join_file_registry inner_join_registry
.where(model_id: model.id, model_type: model.class.name) .where(model_id: model.id, model_type: model.class.name)
end end
def inner_join_file_registry def inner_join_registry
joins(:registry) joins(:registry)
end end
def missing_file_registry def missing_registry
left_outer_join_file_registry left_outer_join_registry
.where(file_registry_table[:id].eq(nil)) .where(registry_table[:id].eq(nil))
end end
# Searches for a list of uploads based on the query given in `query`. # Searches for a list of uploads based on the query given in `query`.
...@@ -40,15 +40,15 @@ module Geo ...@@ -40,15 +40,15 @@ module Geo
private private
def file_registry_table def registry_table
Geo::UploadRegistry.arel_table Geo::UploadRegistry.arel_table
end end
def left_outer_join_file_registry def left_outer_join_registry
join_statement = join_statement =
arel_table arel_table
.join(file_registry_table, Arel::Nodes::OuterJoin) .join(registry_table, Arel::Nodes::OuterJoin)
.on(arel_table[:id].eq(file_registry_table[:file_id])) .on(arel_table[:id].eq(registry_table[:file_id]))
joins(join_statement.join_sources) joins(join_statement.join_sources)
end end
......
...@@ -14,10 +14,10 @@ module Gitlab ...@@ -14,10 +14,10 @@ module Gitlab
class Fdw class Fdw
class LfsObjectRegistryQueryBuilder < BaseQueryBuilder class LfsObjectRegistryQueryBuilder < BaseQueryBuilder
# rubocop:disable CodeReuse/ActiveRecord # rubocop:disable CodeReuse/ActiveRecord
def for_lfs_objects(lfs_object_ids) def for_lfs_objects(ids)
query query
.joins(fdw_inner_join_lfs_objects) .joins(fdw_inner_join_lfs_objects)
.lfs_object_id_in(lfs_object_ids) .lfs_object_id_in(ids)
end end
# rubocop:enable CodeReuse/ActiveRecord # rubocop:enable CodeReuse/ActiveRecord
...@@ -25,21 +25,21 @@ module Gitlab ...@@ -25,21 +25,21 @@ module Gitlab
def base def base
::Geo::LfsObjectRegistry ::Geo::LfsObjectRegistry
.select(lfs_registry_table[Arel.star]) .select(registry_table[Arel.star])
end end
def lfs_registry_table def registry_table
::Geo::LfsObjectRegistry.arel_table ::Geo::LfsObjectRegistry.arel_table
end end
def fdw_lfs_object_table def fdw_table
::Geo::Fdw::LfsObject.arel_table ::Geo::Fdw::LfsObject.arel_table
end end
def fdw_inner_join_lfs_objects def fdw_inner_join_lfs_objects
lfs_registry_table registry_table
.join(fdw_lfs_object_table, Arel::Nodes::InnerJoin) .join(fdw_table, Arel::Nodes::InnerJoin)
.on(lfs_registry_table[:lfs_object_id].eq(fdw_lfs_object_table[:id])) .on(registry_table[:lfs_object_id].eq(fdw_table[:id]))
.join_sources .join_sources
end end
end end
......
...@@ -17,8 +17,8 @@ module Gitlab ...@@ -17,8 +17,8 @@ module Gitlab
query query
.joins(fdw_inner_join_uploads) .joins(fdw_inner_join_uploads)
.where( .where(
fdw_upload_table[:model_id].eq(model.id) fdw_table[:model_id].eq(model.id)
.and(fdw_upload_table[:model_type].eq(model.class.name)) .and(fdw_table[:model_type].eq(model.class.name))
) )
) )
end end
...@@ -27,21 +27,21 @@ module Gitlab ...@@ -27,21 +27,21 @@ module Gitlab
private private
def base def base
::Geo::UploadRegistry.select(file_registry_table[Arel.star]) ::Geo::UploadRegistry.select(registry_table[Arel.star])
end end
def file_registry_table def registry_table
::Geo::UploadRegistry.arel_table ::Geo::UploadRegistry.arel_table
end end
def fdw_upload_table def fdw_table
::Geo::Fdw::Upload.arel_table ::Geo::Fdw::Upload.arel_table
end end
def fdw_inner_join_uploads def fdw_inner_join_uploads
file_registry_table registry_table
.join(fdw_upload_table, Arel::Nodes::InnerJoin) .join(fdw_table, Arel::Nodes::InnerJoin)
.on(file_registry_table[:file_id].eq(fdw_upload_table[:id])) .on(registry_table[:file_id].eq(fdw_table[:id]))
.join_sources .join_sources
end end
end end
......
...@@ -8,7 +8,7 @@ RSpec.describe Geo::Fdw::LfsObject, :geo, type: :model do ...@@ -8,7 +8,7 @@ RSpec.describe Geo::Fdw::LfsObject, :geo, type: :model do
it { is_expected.to have_many(:projects).class_name('Geo::Fdw::Project').through(:lfs_objects_projects) } it { is_expected.to have_many(:projects).class_name('Geo::Fdw::Project').through(:lfs_objects_projects) }
end end
describe '.missing_file_registry', :geo_fdw do describe '.missing_registry', :geo_fdw do
it "returns lfs objects that don't have a corresponding registry entry" do it "returns lfs objects that don't have a corresponding registry entry" do
missing_registry_entries = create_list(:lfs_object, 2) missing_registry_entries = create_list(:lfs_object, 2)
...@@ -16,7 +16,7 @@ RSpec.describe Geo::Fdw::LfsObject, :geo, type: :model do ...@@ -16,7 +16,7 @@ RSpec.describe Geo::Fdw::LfsObject, :geo, type: :model do
create(:geo_lfs_object_registry, lfs_object_id: lfs.id) create(:geo_lfs_object_registry, lfs_object_id: lfs.id)
end end
expect(described_class.missing_file_registry).to match_ids(missing_registry_entries) expect(described_class.missing_registry).to match_ids(missing_registry_entries)
end end
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