Commit 6ee2dfe7 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch...

Merge branch '207049-geo-query-to-retrieve-job-artifacts-always-use-the-selective-sync-version' into 'master'

Resolve "Geo - Query to retrieve Job Artifacts always use the selective sync version"

Closes #207049

See merge request gitlab-org/gitlab!25388
parents eb5797a2 f4373a62
......@@ -27,7 +27,7 @@ module Geo
end
def job_artifacts
Geo::Fdw::Ci::JobArtifact.all unless selective_sync?
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)
......
......@@ -219,7 +219,7 @@ class GeoNode < ApplicationRecord
end
def job_artifacts
Ci::JobArtifact.all unless selective_sync?
return Ci::JobArtifact.all unless selective_sync?
Ci::JobArtifact.project_id_in(projects)
end
......
---
title: Geo - Fix query to retrieve Job Artifacts when selective sync is disabled
merge_request: 25388
author:
type: performance
......@@ -131,4 +131,24 @@ RSpec.describe Geo::Fdw::GeoNode, :geo, type: :model do
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
......@@ -744,4 +744,26 @@ describe GeoNode, :request_store, :geo, type: :model do
end
end
end
describe '#job_artifacts' do
context 'when selective sync is enabled' do
it 'applies project restriction' do
node.update!(selective_sync_type: 'namespaces')
expect(Ci::JobArtifact).to receive(:project_id_in).once.and_call_original
node.job_artifacts
end
end
context 'when selective sync is disabled' do
it 'does not apply project restriction' do
node.update!(selective_sync_type: nil)
expect(Ci::JobArtifact).not_to receive(:project_id_in)
node.job_artifacts
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