Commit c48976f5 authored by Alex Kalderimis's avatar Alex Kalderimis

Rename with_service to with_integration

This method eagerly loads an integration association.
parent 7c1f5b41
......@@ -550,7 +550,7 @@ class Project < ApplicationRecord
scope :with_namespace, -> { includes(:namespace) }
scope :with_import_state, -> { includes(:import_state) }
scope :include_project_feature, -> { includes(:project_feature) }
scope :with_service, ->(service) { joins(service).eager_load(service) }
scope :with_integration, ->(integration) { joins(integration).eager_load(integration) }
scope :with_shared_runners, -> { where(shared_runners_enabled: true) }
scope :with_container_registry, -> { where(container_registry_enabled: true) }
scope :inside_path, ->(path) do
......
......@@ -15,7 +15,7 @@ module Clusters
raise cluster_missing_error(integration_name) unless cluster
integration = ::Project.integration_association_name(integration_name).to_sym
cluster.all_projects.with_service(integration).find_each do |project|
cluster.all_projects.with_integration(integration).find_each do |project|
project.public_send(integration).update!(active: false) # rubocop:disable GitlabSecurity/PublicSend
end
end
......
......@@ -1557,13 +1557,16 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '.with_service' do
describe '.with_integration' do
before do
create_list(:prometheus_project, 2)
end
it 'avoid n + 1' do
expect { described_class.with_service(:prometheus_integration).map(&:prometheus_integration) }.not_to exceed_query_limit(1)
let(:integration) { :prometheus_integration }
it 'avoids n + 1' do
expect { described_class.with_service(integration).map(&integration) }
.not_to exceed_query_limit(1)
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