Commit 2f5873d1 authored by Patrick Bair's avatar Patrick Bair

Merge branch '340781-fix-cross-join-upstream-downstream-projects' into 'master'

Remove cross-joins from Project#upstream_projects,#downstream_projects

See merge request gitlab-org/gitlab!71247
parents 72148118 239dd6a1
---
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
...@@ -191,7 +191,7 @@ module EE ...@@ -191,7 +191,7 @@ module EE
def project_has_subscriptions? def project_has_subscriptions?
project.feature_available?(:ci_project_subscriptions) && project.feature_available?(:ci_project_subscriptions) &&
project.downstream_projects.any? project.downstream_project_subscriptions.any?
end end
def merge_train_ref? def merge_train_ref?
......
...@@ -93,9 +93,9 @@ module EE ...@@ -93,9 +93,9 @@ module EE
has_many :project_aliases 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_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_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 has_many :sourced_pipelines, class_name: 'Ci::Sources::Project', foreign_key: :source_project_id
...@@ -795,6 +795,14 @@ module EE ...@@ -795,6 +795,14 @@ module EE
available_features[feature] available_features[feature]
end end
def upstream_projects_count
upstream_project_subscriptions.count
end
def downstream_projects_count
downstream_project_subscriptions.count
end
def merge_pipelines_enabled? def merge_pipelines_enabled?
return false unless ci_cd_settings return false unless ci_cd_settings
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
%h5 %h5
= _("Subscriptions") = _("Subscriptions")
%span.badge.badge-pill %span.badge.badge-pill
= @project.upstream_projects.count + @project.downstream_projects.count = @project.upstream_projects_count + @project.downstream_projects_count
%table.table.gl-mt-3 %table.table.gl-mt-3
%thead %thead
......
...@@ -3032,6 +3032,54 @@ RSpec.describe Project do ...@@ -3032,6 +3032,54 @@ RSpec.describe Project do
end end
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 '#upstream_projects_count' do
it 'returns the upstream projects count' do
primary_project = create(:project, :public)
upstream_projects = create_list(:project, 2, :public)
primary_project.upstream_projects = upstream_projects
with_cross_joins_prevented do
expect(primary_project.upstream_projects_count).to eq(2)
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 '#downstream_projects_count' do
it 'returns the downstream projects count' do
primary_project = create(:project, :public)
downstream_projects = create_list(:project, 2, :public)
primary_project.downstream_projects = downstream_projects
with_cross_joins_prevented do
expect(primary_project.downstream_projects_count).to eq(2)
end
end
end
describe '#vulnerability_report_rule' do describe '#vulnerability_report_rule' do
subject { project.vulnerability_report_rule } 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