Commit 7f3083f0 authored by Michael Kozono's avatar Michael Kozono

Merge branch '217477-remove-fdw-models-for-job-artifacts' into 'master'

Geo - Remove unused Geo::Fdw::Ci::JobArtifact model

Closes #217477

See merge request gitlab-org/gitlab!34592
parents b83174a3 f612ad12
# frozen_string_literal: true
module Geo
module Fdw
module Ci
class JobArtifact < ::Geo::BaseFdw
include ObjectStorable
STORE_COLUMN = :file_store
self.table_name = Gitlab::Geo::Fdw.foreign_table_name('ci_job_artifacts')
belongs_to :project, class_name: 'Geo::Fdw::Project', inverse_of: :job_artifacts
scope :not_expired, -> { where('expire_at IS NULL OR expire_at > ?', Time.current) }
scope :project_id_in, ->(ids) { where(project_id: ids) }
class << self
def inner_join_job_artifact_registry
join_statement =
arel_table
.join(job_artifact_registry_table, Arel::Nodes::InnerJoin)
.on(arel_table[:id].eq(job_artifact_registry_table[:artifact_id]))
joins(join_statement.join_sources)
end
def missing_job_artifact_registry
left_outer_join_job_artifact_registry
.where(job_artifact_registry_table[:id].eq(nil))
end
private
def job_artifact_registry_table
Geo::JobArtifactRegistry.arel_table
end
def left_outer_join_job_artifact_registry
join_statement =
arel_table
.join(job_artifact_registry_table, Arel::Nodes::OuterJoin)
.on(arel_table[:id].eq(job_artifact_registry_table[:artifact_id]))
joins(join_statement.join_sources)
end
end
end
end
end
end
...@@ -26,25 +26,6 @@ module Geo ...@@ -26,25 +26,6 @@ module Geo
projects.inner_join_project_registry projects.inner_join_project_registry
end end
def job_artifacts
return Geo::Fdw::Ci::JobArtifact.all unless selective_sync?
query = Geo::Fdw::Ci::JobArtifact.project_id_in(projects).select(:id)
cte = Gitlab::SQL::CTE.new(:restricted_job_artifacts, query)
fdw_job_artifact_table = Geo::Fdw::Ci::JobArtifact.arel_table
inner_join_restricted_job_artifacts =
cte.table
.join(fdw_job_artifact_table, Arel::Nodes::InnerJoin)
.on(cte.table[:id].eq(fdw_job_artifact_table[:id]))
.join_sources
Geo::Fdw::Ci::JobArtifact
.with(cte.to_arel)
.from(cte.table)
.joins(inner_join_restricted_job_artifacts)
end
def projects def projects
return Geo::Fdw::Project.all unless selective_sync? return Geo::Fdw::Project.all unless selective_sync?
......
...@@ -9,7 +9,6 @@ module Geo ...@@ -9,7 +9,6 @@ module Geo
self.primary_key = :id self.primary_key = :id
self.table_name = Gitlab::Geo::Fdw.foreign_table_name('projects') self.table_name = Gitlab::Geo::Fdw.foreign_table_name('projects')
has_many :job_artifacts, class_name: 'Geo::Fdw::Ci::JobArtifact'
has_many :container_repositories, class_name: 'Geo::Fdw::ContainerRepository' has_many :container_repositories, class_name: 'Geo::Fdw::ContainerRepository'
belongs_to :namespace, class_name: 'Geo::Fdw::Namespace' belongs_to :namespace, class_name: 'Geo::Fdw::Namespace'
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::Fdw::Ci::JobArtifact, :geo, type: :model do
context 'relationships' do
it { is_expected.to belong_to(:project).class_name('Geo::Fdw::Project').inverse_of(:job_artifacts) }
end
end
...@@ -131,24 +131,4 @@ RSpec.describe Geo::Fdw::GeoNode, :geo, type: :model do ...@@ -131,24 +131,4 @@ RSpec.describe Geo::Fdw::GeoNode, :geo, type: :model do
end end
end end
end end
describe '#job_artifacts', :geo_fdw do
subject { described_class.find(node.id) }
context 'when selective sync is enabled' do
it 'applies a CTE statement' do
node.update!(selective_sync_type: 'namespaces')
expect(subject.job_artifacts.to_sql).to match(/WITH .+restricted_job_artifacts/)
end
end
context 'when selective sync is disabled' do
it 'doest not apply a CTE statement' do
node.update!(selective_sync_type: nil)
expect(subject.job_artifacts.to_sql).not_to match(/WITH .+restricted_job_artifacts/)
end
end
end
end end
...@@ -4,7 +4,6 @@ require 'spec_helper' ...@@ -4,7 +4,6 @@ require 'spec_helper'
RSpec.describe Geo::Fdw::Project, :geo_fdw, type: :model do RSpec.describe Geo::Fdw::Project, :geo_fdw, type: :model do
context 'relationships' do context 'relationships' do
it { is_expected.to have_many(:job_artifacts).class_name('Geo::Fdw::Ci::JobArtifact') }
it { is_expected.to have_many(:container_repositories).class_name('Geo::Fdw::ContainerRepository') } it { is_expected.to have_many(:container_repositories).class_name('Geo::Fdw::ContainerRepository') }
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