Commit 32d9cf69 authored by Arturo Herrero's avatar Arturo Herrero

Improve update_all when FROM is a subquery

After working in
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/46260, we have
learned that the UPDATE statement was incorrect because the SQL code
doesn't include the subquery.

This change partially reverts the changes in c2b330dc.

This is not a bug because:
- If a project has an issue tracker integration or an external wiki
  integration, `has_external_issue_tracker`/`has_external_wiki` is
  already `true`, so we just were updating it again with `true`. This
  commit avoids this scenario.
- If a project doesn't have an issue tracker integration or an external
  wiki integration, `has_external_issue_tracker`/`has_external_wiki` is
  `false`, so we update it to `true`.
parent e70f863d
...@@ -33,15 +33,17 @@ class BulkCreateIntegrationService ...@@ -33,15 +33,17 @@ class BulkCreateIntegrationService
klass.insert_all(items_to_insert, returning: [:id]) klass.insert_all(items_to_insert, returning: [:id])
end end
# rubocop: disable CodeReuse/ActiveRecord
def run_callbacks(batch) def run_callbacks(batch)
if integration.external_issue_tracker? if integration.external_issue_tracker?
batch.update_all(has_external_issue_tracker: true) Project.where(id: batch.select(:id)).update_all(has_external_issue_tracker: true)
end end
if integration.external_wiki? if integration.external_wiki?
batch.update_all(has_external_wiki: true) Project.where(id: batch.select(:id)).update_all(has_external_wiki: true)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def service_hash def service_hash
if integration.template? if integration.template?
......
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