Commit 2295c37f authored by Adam Hegyi's avatar Adam Hegyi Committed by Igor Drozdov

Cross-join fix for devops adoption

parent 6c3826c0
...@@ -61,7 +61,9 @@ module Analytics ...@@ -61,7 +61,9 @@ module Analytics
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def runner_configured def runner_configured
Ci::Runner.active.belonging_to_group_or_project(snapshot_groups, snapshot_project_ids).exists? ::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/337541') do
Ci::Runner.active.belonging_to_group_or_project(snapshot_groups, snapshot_project_ids).exists?
end
end end
def pipeline_succeeded def pipeline_succeeded
...@@ -119,10 +121,16 @@ module Analytics ...@@ -119,10 +121,16 @@ module Analytics
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def projects_count_with_artifact(artifacts_scope) def projects_count_with_artifact(artifacts_scope)
subquery = artifacts_scope.created_in_time_range(from: range_start, to: range_end) subquery = artifacts_scope.created_in_time_range(from: range_start, to: range_end)
.where(Ci::JobArtifact.arel_table[:project_id].eq(Project.arel_table[:id])).arel.exists .where(Ci::JobArtifact.arel_table[:project_id].eq(Arel.sql('project_ids.id'))).arel.exists
snapshot_project_ids.each_slice(1000).sum do |project_ids| snapshot_project_ids.each_slice(1000).sum do |project_ids|
Project.where(id: project_ids).where(subquery).count ids = project_ids.map { |id| [id] }
# To avoid cross-database join, we swap out the FROM part with just the project_ids we need
Project
.select(:id)
.from("(#{Arel::Nodes::ValuesList.new(ids).to_sql}) project_ids (id)")
.where(subquery)
.count
end end
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
- "./ee/spec/finders/ee/namespaces/projects_finder_spec.rb" - "./ee/spec/finders/ee/namespaces/projects_finder_spec.rb"
- "./ee/spec/finders/security/findings_finder_spec.rb" - "./ee/spec/finders/security/findings_finder_spec.rb"
- "./ee/spec/graphql/ee/resolvers/namespace_projects_resolver_spec.rb" - "./ee/spec/graphql/ee/resolvers/namespace_projects_resolver_spec.rb"
- "./ee/spec/lib/analytics/devops_adoption/snapshot_calculator_spec.rb"
- "./ee/spec/lib/ee/gitlab/background_migration/migrate_approver_to_approval_rules_spec.rb" - "./ee/spec/lib/ee/gitlab/background_migration/migrate_approver_to_approval_rules_spec.rb"
- "./ee/spec/lib/ee/gitlab/background_migration/migrate_security_scans_spec.rb" - "./ee/spec/lib/ee/gitlab/background_migration/migrate_security_scans_spec.rb"
- "./ee/spec/lib/ee/gitlab/background_migration/populate_latest_pipeline_ids_spec.rb" - "./ee/spec/lib/ee/gitlab/background_migration/populate_latest_pipeline_ids_spec.rb"
......
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