diff --git a/app/controllers/active_storage/representations_controller.rb b/app/controllers/active_storage/representations_controller.rb index 928d292f1..68cca5585 100644 --- a/app/controllers/active_storage/representations_controller.rb +++ b/app/controllers/active_storage/representations_controller.rb @@ -31,7 +31,9 @@ module ActiveStorage unless processing ActiveStorage::PreviewJob.perform_later(@blob.id) - @blob.attachments.take.record.update(file_processing: true) + ActiveRecord::Base.no_touching do + @blob.attachments.take.record.update(file_processing: true) + end end false diff --git a/app/jobs/active_storage/preview_job.rb b/app/jobs/active_storage/preview_job.rb index f1eda5812..2d1941ca6 100644 --- a/app/jobs/active_storage/preview_job.rb +++ b/app/jobs/active_storage/preview_job.rb @@ -6,7 +6,9 @@ class ActiveStorage::PreviewJob < ActiveStorage::BaseJob discard_on StandardError do |job, error| blob = ActiveStorage::Blob.find_by(id: job.arguments.first) - blob&.attachments&.take&.record&.update(file_processing: false) + ActiveRecord::Base.no_touching do + blob&.attachments&.take&.record&.update(file_processing: false) + end Rails.logger.error "Couldn't generate preview for Blob with id: #{job.arguments.first}. Error:\n #{error}" end @@ -24,6 +26,8 @@ class ActiveStorage::PreviewJob < ActiveStorage::BaseJob Rails.logger.info "Preview for the Blod with id: #{blob.id} - successfully generated.\n" \ "Transformations applied: #{preview.variation.transformations}" - blob.attachments.take.record.update(file_processing: false) + ActiveRecord::Base.no_touching do + blob.attachments.take.record.update(file_processing: false) + end end end diff --git a/app/models/asset.rb b/app/models/asset.rb index 982e2af99..ea036f300 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -32,17 +32,15 @@ class Asset < ApplicationRecord optional: true belongs_to :team, optional: true has_one :step_asset, inverse_of: :asset, dependent: :destroy - has_one :step, through: :step_asset, dependent: :nullify + has_one :step, through: :step_asset, touch: true, dependent: :nullify has_one :result_asset, inverse_of: :asset, dependent: :destroy - has_one :result, through: :result_asset, dependent: :nullify + has_one :result, through: :result_asset, touch: true, dependent: :nullify has_one :repository_asset_value, inverse_of: :asset, dependent: :destroy has_one :repository_cell, through: :repository_asset_value, dependent: :nullify has_many :report_elements, inverse_of: :asset, dependent: :destroy has_one :asset_text_datum, inverse_of: :asset, dependent: :destroy - after_save { result&.touch; step&.touch } - attr_accessor :file_content, :file_info, :in_template def self.search( diff --git a/app/models/protocol.rb b/app/models/protocol.rb index 735b9c120..4ddafea6a 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -229,14 +229,16 @@ class Protocol < ApplicationRecord # Deep-clone given array of assets def self.deep_clone_assets(assets_to_clone) - assets_to_clone.each do |src_id, dest_id| - src = Asset.find_by(id: src_id) - dest = Asset.find_by(id: dest_id) - dest.destroy! if src.blank? && dest.present? - next unless src.present? && dest.present? + ActiveRecord::Base.no_touching do + assets_to_clone.each do |src_id, dest_id| + src = Asset.find_by(id: src_id) + dest = Asset.find_by(id: dest_id) + dest.destroy! if src.blank? && dest.present? + next unless src.present? && dest.present? - # Clone file - src.duplicate_file(dest) + # Clone file + src.duplicate_file(dest) + end end end