Commit a12f5d74 authored by Dylan Griffith's avatar Dylan Griffith

Remove cross-joins from Project#upstream_projects,#downstream_projects

These methods were joining between `ci_*` and non `ci_*` tables which is
not going to be allowed when we move `ci_*` tables to a new database.
`disable_joins` was chosen here as this does not increase the
cardinality of data being returned as the only usage of this (aside
from counts handled in the next commit) is
[`project.downstream_projects.each`](
https://gitlab.com/gitlab-org/gitlab/-/blob/0d75b42c4ce663e4a9095348f97e6b84b55ee075/ee/app/services/ci/trigger_downstream_subscription_service.rb#L6
). This is fine to switch to `disable_joins` as there is no pagination,
no limits and no filtering. You can read more at
https://docs.gitlab.com/ee/development/database/multiple_databases.html#use-disable_joins-for-has_one-or-has_many-through-relations
.
parent a8b8d86b
---
name: disable_joins_upstream_downstream_projects
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/71247
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/341791
milestone: '14.4'
type: development
group: group::sharding
default_enabled: false
......@@ -92,9 +92,9 @@ module EE
has_many :project_aliases
has_many :upstream_project_subscriptions, class_name: 'Ci::Subscriptions::Project', foreign_key: :downstream_project_id, inverse_of: :downstream_project
has_many :upstream_projects, class_name: 'Project', through: :upstream_project_subscriptions, source: :upstream_project
has_many :upstream_projects, class_name: 'Project', through: :upstream_project_subscriptions, source: :upstream_project, disable_joins: -> { ::Feature.enabled?(:disable_joins_upstream_downstream_projects, default_enabled: :yaml) }
has_many :downstream_project_subscriptions, class_name: 'Ci::Subscriptions::Project', foreign_key: :upstream_project_id, inverse_of: :upstream_project
has_many :downstream_projects, class_name: 'Project', through: :downstream_project_subscriptions, source: :downstream_project
has_many :downstream_projects, class_name: 'Project', through: :downstream_project_subscriptions, source: :downstream_project, disable_joins: -> { ::Feature.enabled?(:disable_joins_upstream_downstream_projects, default_enabled: :yaml) }
has_many :sourced_pipelines, class_name: 'Ci::Sources::Project', foreign_key: :source_project_id
......
......@@ -2994,6 +2994,30 @@ RSpec.describe Project do
end
end
describe '#upstream_projects' do
it 'returns the upstream projects' do
primary_project = create(:project, :public)
upstream_project = create(:project, :public)
primary_project.upstream_projects << upstream_project
with_cross_joins_prevented do
expect(primary_project.upstream_projects).to eq([upstream_project])
end
end
end
describe '#downstream_projects' do
it 'returns the downstream projects' do
primary_project = create(:project, :public)
downstream_project = create(:project, :public)
primary_project.downstream_projects << downstream_project
with_cross_joins_prevented do
expect(primary_project.downstream_projects).to eq([downstream_project])
end
end
end
describe '#vulnerability_report_rule' do
subject { project.vulnerability_report_rule }
......
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