Commit d308d767 authored by Arturo Herrero's avatar Arturo Herrero

Merge branch '218252-update-project-overrides-query' into 'master'

Update project overrides query

See merge request gitlab-org/gitlab!59168
parents 33671cac cc6f35d7
......@@ -6,12 +6,12 @@ module Integration
class_methods do
def with_custom_integration_for(integration, page = nil, per = nil)
custom_integration_project_ids = Service
.select(:project_id)
.where(type: integration.type)
.where(inherit_from_id: nil)
.distinct # Required until https://gitlab.com/gitlab-org/gitlab/-/issues/207385
.where.not(project_id: nil)
.page(page)
.per(per)
.pluck(:project_id)
Project.where(id: custom_integration_project_ids)
end
......
---
title: Add index services on project and type where inherit is null
merge_request: 59168
author:
type: other
# frozen_string_literal: true
class AddIndexServicesOnProjectAndTypeWhereInheritNull < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
INDEX_NAME = 'index_services_on_project_and_type_where_inherit_null'
def up
add_concurrent_index(:services, [:project_id, :type], where: 'inherit_from_id IS NULL', name: INDEX_NAME)
end
def down
remove_concurrent_index_by_name(:services, INDEX_NAME)
end
end
843d9eabf8b67fe10d9eb453e887032d5b88b8594ae666bc6c6ac81e20e1ab53
\ No newline at end of file
......@@ -23864,6 +23864,8 @@ CREATE INDEX index_service_desk_enabled_projects_on_id_creator_id_created_at ON
CREATE INDEX index_services_on_inherit_from_id ON services USING btree (inherit_from_id);
CREATE INDEX index_services_on_project_and_type_where_inherit_null ON services USING btree (project_id, type) WHERE (inherit_from_id IS NULL);
CREATE UNIQUE INDEX index_services_on_project_id_and_type_unique ON services USING btree (project_id, type);
CREATE INDEX index_services_on_template ON services USING btree (template);
......@@ -6,23 +6,28 @@ RSpec.describe Integration do
let_it_be(:project_1) { create(:project) }
let_it_be(:project_2) { create(:project) }
let_it_be(:project_3) { create(:project) }
let_it_be(:project_4) { create(:project) }
let_it_be(:instance_integration) { create(:jira_service, :instance) }
before do
create(:jira_service, project: project_1, inherit_from_id: instance_integration.id)
create(:jira_service, project: project_2, inherit_from_id: nil)
create(:slack_service, project: project_3, inherit_from_id: nil)
create(:jira_service, group: create(:group), project: nil, inherit_from_id: nil)
create(:jira_service, project: project_3, inherit_from_id: nil)
create(:slack_service, project: project_4, inherit_from_id: nil)
end
describe '.with_custom_integration_for' do
it 'returns projects with custom integrations' do
expect(Project.with_custom_integration_for(instance_integration)).to contain_exactly(project_2)
# We use pagination to verify that the group is excluded from the query
expect(Project.with_custom_integration_for(instance_integration, 0, 2)).to contain_exactly(project_2, project_3)
expect(Project.with_custom_integration_for(instance_integration)).to contain_exactly(project_2, project_3)
end
end
describe '.without_integration' do
it 'returns projects without integration' do
expect(Project.without_integration(instance_integration)).to contain_exactly(project_3)
expect(Project.without_integration(instance_integration)).to contain_exactly(project_4)
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