Commit f59fb5f0 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'fix_devops_adoption_snapshot_calculator_wrong_connection' into 'master'

Fix query using wrong connection

See merge request gitlab-org/gitlab!80116
parents 94105ea9 b4ec8ddf
...@@ -118,17 +118,8 @@ module Analytics ...@@ -118,17 +118,8 @@ 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)
.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|
ids = project_ids.map { |id| [id] } artifacts_scope.created_in_time_range(from: range_start, to: range_end).where(project_id: project_ids).count
# 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
......
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