'Rails bulk_import should ignore Active Storage association
I'm bulk importing many calculated records. Can i tell rails to ignore the association during the bulk_import?
Rails Version 5.2.6
Import code is:
MachineAssignment.import all_assignments, on_duplicate_key_update: [:start, :end, :is_calculated, :state]
My Model MachineAssignment has Active Storage Attachments
class MachineAssignment < ApplicationRecord
has_one_attached :toollist
has_one_attached :setting
has_one_attached :code
end
During the bulk import rails selects every MachineAssignment to Active Storage Association. This takes time and slows down the import. Although nothing is changed on Active Storage associated files.
I also tried to preload the association, this speeds it up but is still slower and also not needed.
ActiveRecord::Associations::Preloader.new.preload(all_jobs, :machine_assignments => [:progresses, setting_attachment: :blob, toollist_attachment: :blob, code_attachment: :blob])
Before Active Storage we used Paperclip. And in Paperclip the attachments where stored as fields within the same table row and the Association was not there.
Any thoughts on how to speed this bulk_import up or ignore the association to Active Storage?
best regards
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
