Commit 1c67875c authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '205128-geo-remove-fdw-lfs-related-models' into 'master'

Geo - Remove unused FDW queries and models for LFS objects

Closes #205128

See merge request gitlab-org/gitlab!33548
parents 9af9ec98 de9c17c2
......@@ -45,32 +45,6 @@ module Geo
.joins(inner_join_restricted_job_artifacts)
end
def lfs_objects
return Geo::Fdw::LfsObject.all unless selective_sync?
query = Geo::Fdw::LfsObjectsProject.project_id_in(projects).select(:lfs_object_id)
cte = Gitlab::SQL::CTE.new(:restricted_lfs_objects, query)
fdw_lfs_object_table = Geo::Fdw::LfsObject.arel_table
inner_join_restricted_lfs_objects =
cte.table
.join(fdw_lfs_object_table, Arel::Nodes::InnerJoin)
.on(cte.table[:lfs_object_id].eq(fdw_lfs_object_table[:id]))
.join_sources
Geo::Fdw::LfsObject
.with(cte.to_arel)
.from(cte.table)
.joins(inner_join_restricted_lfs_objects)
end
def lfs_object_registries
return Geo::LfsObjectRegistry.all unless selective_sync?
Gitlab::Geo::Fdw::LfsObjectRegistryQueryBuilder.new
.for_lfs_objects(lfs_objects)
end
def projects
return Geo::Fdw::Project.all unless selective_sync?
......
# frozen_string_literal: true
module Geo
module Fdw
class LfsObject < ::Geo::BaseFdw
include ObjectStorable
STORE_COLUMN = :file_store
self.primary_key = :id
self.table_name = Gitlab::Geo::Fdw.foreign_table_name('lfs_objects')
has_many :lfs_objects_projects, class_name: 'Geo::Fdw::LfsObjectsProject'
has_many :projects, class_name: 'Geo::Fdw::Project', through: :lfs_objects_projects
scope :project_id_in, ->(ids) { joins(:projects).merge(Geo::Fdw::Project.id_in(ids)) }
class << self
def failed
inner_join_registry
.merge(Geo::LfsObjectRegistry.failed)
end
def inner_join_registry
join_statement =
arel_table
.join(registry_table, Arel::Nodes::InnerJoin)
.on(arel_table[:id].eq(registry_table[:lfs_object_id]))
joins(join_statement.join_sources)
end
def missing_registry
left_outer_join_registry
.where(registry_table[:id].eq(nil))
end
def missing_on_primary
inner_join_registry
.merge(Geo::LfsObjectRegistry.synced.missing_on_primary)
end
def synced
inner_join_registry
.merge(Geo::LfsObjectRegistry.synced)
end
private
def registry_table
Geo::LfsObjectRegistry.arel_table
end
def left_outer_join_registry
join_statement =
arel_table
.join(registry_table, Arel::Nodes::OuterJoin)
.on(arel_table[:id].eq(registry_table[:lfs_object_id]))
joins(join_statement.join_sources)
end
end
end
end
end
# frozen_string_literal: true
module Geo
module Fdw
class LfsObjectsProject < ::Geo::BaseFdw
self.table_name = Gitlab::Geo::Fdw.foreign_table_name('lfs_objects_projects')
belongs_to :lfs_object, class_name: 'Geo::Fdw::LfsObject', inverse_of: :projects
belongs_to :project, class_name: 'Geo::Fdw::Project', inverse_of: :lfs_objects
scope :project_id_in, ->(ids) { where(project_id: ids) }
end
end
end
......@@ -10,8 +10,6 @@ module Geo
self.table_name = Gitlab::Geo::Fdw.foreign_table_name('projects')
has_many :job_artifacts, class_name: 'Geo::Fdw::Ci::JobArtifact'
has_many :lfs_objects_projects, class_name: 'Geo::Fdw::LfsObjectsProject'
has_many :lfs_objects, class_name: 'Geo::Fdw::LfsObject', through: :lfs_objects_projects
has_many :container_repositories, class_name: 'Geo::Fdw::ContainerRepository'
belongs_to :namespace, class_name: 'Geo::Fdw::Namespace'
......
# frozen_string_literal: true
# Builder class to create composable queries using FDW to
# retrieve file registries for LFS objects.
#
# Basic usage:
#
# Gitlab::Geo::Fdw::LfsObjectRegistryQueryBuilder
# .new
# .inner_join_lfs_objects
#
module Gitlab
module Geo
class Fdw
class LfsObjectRegistryQueryBuilder < BaseQueryBuilder
# rubocop:disable CodeReuse/ActiveRecord
def for_lfs_objects(ids)
query
.joins(fdw_inner_join_lfs_objects)
.model_id_in(ids)
end
# rubocop:enable CodeReuse/ActiveRecord
private
def base
::Geo::LfsObjectRegistry
.select(registry_table[Arel.star])
end
def registry_table
::Geo::LfsObjectRegistry.arel_table
end
def fdw_table
::Geo::Fdw::LfsObject.arel_table
end
def fdw_inner_join_lfs_objects
registry_table
.join(fdw_table, Arel::Nodes::InnerJoin)
.on(registry_table[:lfs_object_id].eq(fdw_table[:id]))
.join_sources
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::Fdw::LfsObject, :geo, type: :model do
context 'relationships' do
it { is_expected.to have_many(:lfs_objects_projects).class_name('Geo::Fdw::LfsObjectsProject') }
it { is_expected.to have_many(:projects).class_name('Geo::Fdw::Project').through(:lfs_objects_projects) }
end
describe '.missing_registry', :geo_fdw do
it "returns lfs objects that don't have a corresponding registry entry" do
missing_registry_entries = create_list(:lfs_object, 2)
create_list(:lfs_object, 2).each do |lfs|
create(:geo_lfs_object_registry, lfs_object_id: lfs.id)
end
expect(described_class.missing_registry).to match_ids(missing_registry_entries)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::Fdw::LfsObjectsProject, :geo, type: :model do
context 'relationships' do
it { is_expected.to belong_to(:lfs_object).class_name('Geo::Fdw::LfsObject').inverse_of(:projects) }
it { is_expected.to belong_to(:project).class_name('Geo::Fdw::Project').inverse_of(:lfs_objects) }
end
end
......@@ -5,8 +5,6 @@ require 'spec_helper'
RSpec.describe Geo::Fdw::Project, :geo_fdw, type: :model do
context 'relationships' do
it { is_expected.to have_many(:job_artifacts).class_name('Geo::Fdw::Ci::JobArtifact') }
it { is_expected.to have_many(:lfs_objects_projects).class_name('Geo::Fdw::LfsObjectsProject') }
it { is_expected.to have_many(:lfs_objects).class_name('Geo::Fdw::LfsObject').through(:lfs_objects_projects) }
it { is_expected.to have_many(:container_repositories).class_name('Geo::Fdw::ContainerRepository') }
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