このコミットが含まれているのは:
2026-06-25 17:40:34 +09:00
コミット 377a09ed70
22個のファイルの変更679行の追加231行の削除
+49
ファイルの表示
@@ -0,0 +1,49 @@
class MaterialSyncImporter
Result = Struct.new(:material, :suppressed, :suppression, keyword_init: true)
def self.import! attributes
new(attributes).import!
end
def initialize attributes
@attributes = attributes
end
def import!
source = source_attributes
key = normalized_source_key(source)
raise ArgumentError, 'normalized_source_key is required for material sync' if key.blank?
suppression = MaterialSyncSuppressionMatcher.match(**source)
return Result.new(material: nil, suppressed: true, suppression:) if suppression
material =
Material
.unscoped
.find_or_initialize_by(normalized_source_key: key)
material.assign_attributes(material_attributes.merge(source))
material.save!
Result.new(material:, suppressed: false, suppression: nil)
end
private
def source_attributes
{ source_kind: @attributes[:source_kind],
source_uri: @attributes[:source_uri],
source_path: @attributes[:source_path],
source_file_id: @attributes[:source_file_id] }
end
def normalized_source_key source
MaterialSyncSuppression.normalize_source_key(source_kind: source[:source_kind],
source_uri: source[:source_uri],
source_path: source[:source_path],
source_file_id: source[:source_file_id])
end
def material_attributes
@attributes.except(:source_kind, :source_uri, :source_path, :source_file_id)
end
end
+22
ファイルの表示
@@ -0,0 +1,22 @@
class MaterialSyncSuppressionMatcher
def self.match source_kind:,
source_uri: nil,
drive_path: nil,
drive_file_id: nil,
source_path: nil,
source_file_id: nil
key = MaterialSyncSuppression.normalize_source_key(source_kind:,
source_uri:,
drive_path:,
drive_file_id:,
source_path:,
source_file_id:)
return nil if key.blank?
MaterialSyncSuppression.find_by(normalized_source_key: key)
end
def self.suppressed?(...)
match(...).present?
end
end
+37
ファイルの表示
@@ -0,0 +1,37 @@
class MaterialSyncSuppressionRegistrar
def self.create! attributes, created_by_user:
new(attributes, created_by_user:).create!
end
def initialize attributes, created_by_user:
@attributes = attributes
@created_by_user = created_by_user
end
def create!
suppression = nil
MaterialSyncSuppression.transaction do
suppression = MaterialSyncSuppression.create!(
@attributes.merge(created_by_user: @created_by_user))
discard_existing_materials!(suppression)
end
suppression
end
private
def discard_existing_materials! suppression
Material.unscoped
.kept
.where(normalized_source_key: suppression.normalized_source_key)
.find_each do |material|
MaterialVersionRecorder.ensure_snapshot!(material, created_by_user: @created_by_user)
material.discard!
MaterialVersionRecorder.record!(material:,
event_type: :discard,
created_by_user: @created_by_user)
end
end
end
+2 -4
ファイルの表示
@@ -1,5 +1,5 @@
class MaterialVersionRecorder < VersionRecorder
EVENT_TYPES = ['create', 'update', 'discard', 'restore', 'suppress'].freeze
EVENT_TYPES = ['create', 'update', 'discard', 'restore'].freeze
def self.record! material:, event_type:, created_by_user:, file_snapshot: nil
new(material:, event_type:, created_by_user:, file_snapshot:).record!
@@ -40,9 +40,7 @@ class MaterialVersionRecorder < VersionRecorder
file_content_type: file_snapshot[:file_content_type],
file_byte_size: file_snapshot[:file_byte_size],
file_checksum: file_snapshot[:file_checksum],
file_sha256: file_snapshot[:file_sha256],
file_suppressed_at: @record.file_suppressed_at,
file_suppression_reason: @record.file_suppression_reason }
file_sha256: file_snapshot[:file_sha256] }
end
def build_file_snapshot blob
-1
ファイルの表示
@@ -40,7 +40,6 @@ class MaterialZipExporter
.joins(:material)
.merge(Material.kept)
.where(profile: @profile)
.where(materials: { file_suppressed_at: nil })
.order(:export_path)
rows = rows.where(materials: { tag_id: @tag_id }) if @tag_id