Fix protocol repository save/load timestamps [SCI-5067]

This commit is contained in:
Oleksii Kriuchykhin 2020-10-06 13:53:53 +02:00
parent 3a4a166856
commit 7cd12bfb07
4 changed files with 20 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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(

View file

@ -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