Commit 45b1b6a1 authored by Arturo Herrero's avatar Arturo Herrero

Remove unnecessary retrieving of IDs

parent 45fcb256
...@@ -8,16 +8,11 @@ class BulkUpdateIntegrationService ...@@ -8,16 +8,11 @@ class BulkUpdateIntegrationService
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def execute def execute
# Retrieving the IDs instantiates the ActiveRecord relation (batch)
# into concrete models, otherwise update_all will clear the relation.
# https://stackoverflow.com/q/34811646/462015
batch_ids = batch.pluck(:id)
Service.transaction do Service.transaction do
batch.update_all(service_hash) batch.update_all(service_hash)
if integration.data_fields_present? if integration.data_fields_present?
integration.data_fields.class.where(service_id: batch_ids).update_all(data_fields_hash) integration.data_fields.class.where(service_id: batch.select(:id)).update_all(data_fields_hash)
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