This commit is contained in:
2026-04-19 19:49:56 +09:00
parent 58429c5e8b
commit 2ea08ef4dd
10 changed files with 54 additions and 29 deletions
@@ -7,6 +7,12 @@ class PostVersionRecorder < VersionRecorder
super(record: post, event_type:, created_by_user:)
end
def self.ensure_snapshot! post, created_by_user:
return if post.post_versions.exists?
record!(post:, event_type: :create, created_by_user:)
end
private
def version_class = PostVersion
+12
View File
@@ -7,6 +7,18 @@ class TagVersioning
end
end
def self.ensure_snapshot! tag, created_by_user:
if tag.nico?
return if tag.nico_tag_versions.exists?
NicoTagVersionRecorder.record!(tag:, event_type: :create, created_by_user:)
else
return if tag.tag_versions.exists?
TagVersionRecorder.record!(tag:, event_type: :create, created_by_user:)
end
end
def self.record_tag_snapshot! tag, created_by_user:
event_type =
if tag.nico?
+6 -1
View File
@@ -10,7 +10,10 @@ class VersionRecorder
end
def record!
@record.with_lock do
raise "#{ record_class.name } must be persisted" unless @record.persisted?
ApplicationRecord.transaction do
@record = record_class.unscoped.lock.find(@record.id)
latest = latest_version
if !(latest) && @event_type != 'create'
@@ -54,4 +57,6 @@ class VersionRecorder
def version_association = raise NotImplementedError
def record_key = raise NotImplementedError
def snapshot_attributes = raise NotImplementedError
def record_class = @record.class
end