Commit e9a052c0 authored by Furkan Ayhan's avatar Furkan Ayhan

Merge branch '339621-ci-matchers-cross-database-query' into 'master'

Remove allow database cross join from runner_matchers

See merge request gitlab-org/gitlab!78084
parents fc3c2872 7f4df5cc
...@@ -255,7 +255,6 @@ module Ci ...@@ -255,7 +255,6 @@ module Ci
Arel.sql("(#{arel_tag_names_array.to_sql})") Arel.sql("(#{arel_tag_names_array.to_sql})")
] ]
::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/339621') do
group(*unique_params).pluck('array_agg(ci_runners.id)', *unique_params).map do |values| group(*unique_params).pluck('array_agg(ci_runners.id)', *unique_params).map do |values|
Gitlab::Ci::Matching::RunnerMatcher.new({ Gitlab::Ci::Matching::RunnerMatcher.new({
runner_ids: values[0], runner_ids: values[0],
...@@ -268,7 +267,6 @@ module Ci ...@@ -268,7 +267,6 @@ module Ci
}) })
end end
end end
end
def runner_matcher def runner_matcher
strong_memoize(:runner_matcher) do strong_memoize(:runner_matcher) do
......
...@@ -33,9 +33,11 @@ RSpec.describe Gitlab::Ci::Minutes::RunnersAvailability do ...@@ -33,9 +33,11 @@ RSpec.describe Gitlab::Ci::Minutes::RunnersAvailability do
end end
end end
context 'N+1 queries' do context 'database queries' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:private_runner) { create(:ci_runner, :project, :online, projects: [project]) } let_it_be(:private_runner) do
create(:ci_runner, :project, :online, projects: [project])
end
it 'caches records loaded from database' do it 'caches records loaded from database' do
ActiveRecord::QueryRecorder.new(skip_cached: false) do ActiveRecord::QueryRecorder.new(skip_cached: false) do
...@@ -44,5 +46,11 @@ RSpec.describe Gitlab::Ci::Minutes::RunnersAvailability do ...@@ -44,5 +46,11 @@ RSpec.describe Gitlab::Ci::Minutes::RunnersAvailability do
expect { minutes.available?(build.build_matcher) }.not_to exceed_all_query_limit(0) expect { minutes.available?(build.build_matcher) }.not_to exceed_all_query_limit(0)
end end
it 'does not join across databases' do
with_cross_joins_prevented do
minutes.available?(build.build_matcher)
end
end
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