Skip to content
代码片段 群组 项目
提交 c2b330dc 编辑于 作者: Arturo Herrero's avatar Arturo Herrero
浏览文件

Fix project callbacks when propagating integrations

After introducing the propagation of integrations using batching and
queues https://gitlab.com/gitlab-org/gitlab/-/merge_requests/42128, we
are not updating the project callbacks: has_external_issue_tracker and
has_external_wiki.

The reason for that is that the batch was uncached but after the merge
request batch is scoped to the query.

In this case, the order is important because we do two things:
- Create the integration for those projects without integration.
- Update has_external_issue_tracker and has_external_wiki in those
  projects.

If we first create the integrations when we then try to update the
callbacks, there is nothing to update since the batch scope is empty at
this time. We have to update first and then create the integrations.
上级 a6a84a12
No related branches found
No related tags found
无相关合并请求
......@@ -11,6 +11,8 @@ def execute
service_list = ServiceList.new(batch, service_hash, association).to_array
Service.transaction do
run_callbacks(batch) if association == 'project'
results = bulk_insert(*service_list)
if integration.data_fields_present?
......@@ -18,8 +20,6 @@ def execute
bulk_insert(*data_list)
end
run_callbacks(batch) if association == 'project'
end
end
......@@ -33,17 +33,15 @@ def bulk_insert(klass, columns, values_array)
klass.insert_all(items_to_insert, returning: [:id])
end
# rubocop: disable CodeReuse/ActiveRecord
def run_callbacks(batch)
if integration.issue_tracker?
Project.where(id: batch.select(:id)).update_all(has_external_issue_tracker: true)
batch.update_all(has_external_issue_tracker: true)
end
if integration.type == 'ExternalWikiService'
Project.where(id: batch.select(:id)).update_all(has_external_wiki: true)
batch.update_all(has_external_wiki: true)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def service_hash
if integration.template?
......
---
title: Fix project callbacks when propagating integrations
merge_request: 45781
author:
type: fixed
......@@ -72,7 +72,7 @@
context 'with a project association' do
let!(:project) { create(:project) }
let(:created_integration) { project.jira_service }
let(:batch) { Project.all }
let(:batch) { Project.without_integration(integration) }
let(:association) { 'project' }
it_behaves_like 'creates integration from batch ids'
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册