tags および tag_names にて論理削除を物理削除に変更 (#416) (#418)

Reviewed-on: #418
Co-authored-by: miteruzo <miteruzo@naver.com>
このコミットはプルリクエスト #418 でマージされました。
このコミットが含まれているのは:
2026-09-21 07:39:58 +09:00
committed by みてるぞ
コミット 785b5ef8bc
15個のファイルの変更388行の追加69行の削除
+1 -1
ファイルの表示
@@ -237,7 +237,7 @@ class MaterialsController < ApplicationController
end
def resolve_material_tag! tag_name_raw
tag_name = TagName.find_undiscard_or_create_by!(name: tag_name_raw)
tag_name = TagName.find_or_create_by!(name: tag_name_raw)
tag = tag_name.tag
tag || Tag.create!(tag_name:, category: :material)
end
+6 -11
ファイルの表示
@@ -573,7 +573,7 @@ class TagsController < ApplicationController
return false
end
target_tag_name = TagName.with_discarded.find_by(name:)
target_tag_name = TagName.find_by(name:)
return true if target_tag_name.nil?
return true if target_tag_name.canonical_id?
@@ -585,17 +585,14 @@ class TagsController < ApplicationController
return if name == tag.name
current_tag_name = tag.tag_name
target_tag_name = TagName.with_discarded.find_by(name:)
target_tag_name = TagName.find_by(name:)
if target_tag_name.nil?
current_tag_name.update!(name:)
return
end
promote_tag_alias!(
tag,
current_tag_name:,
promoted_tag_name: target_tag_name)
promote_tag_alias!(tag, current_tag_name:, promoted_tag_name: target_tag_name)
end
def promote_tag_alias! tag, current_tag_name:, promoted_tag_name:
@@ -605,11 +602,9 @@ class TagsController < ApplicationController
TagVersioning.ensure_snapshot!(old_owner_tag, created_by_user: current_user)
end
promoted_tag_name.undiscard! if promoted_tag_name.discarded?
promoted_tag_name.update!(canonical: nil)
TagName.with_discarded
.where(canonical_id: current_tag_name.id)
TagName.where(canonical_id: current_tag_name.id)
.where.not(id: promoted_tag_name.id)
.find_each do |alias_tag_name|
alias_tag_name.update!(canonical: promoted_tag_name)
@@ -640,7 +635,7 @@ class TagsController < ApplicationController
end
alias_names.each do |alias_name|
alias_tag_name = TagName.find_undiscard_or_create_by!(name: alias_name)
alias_tag_name = TagName.find_or_create_by!(name: alias_name)
affected_tags << alias_tag_name.canonical&.tag
end
@@ -655,7 +650,7 @@ class TagsController < ApplicationController
end
alias_names.each do |alias_name|
alias_tag_name = TagName.find_undiscard_or_create_by!(name: alias_name)
alias_tag_name = TagName.find_or_create_by!(name: alias_name)
alias_tag_name.update!(canonical: tag.tag_name)
end
+1 -1
ファイルの表示
@@ -94,7 +94,7 @@ class WikiPagesController < ApplicationController
return render_unprocessable_entity('タイトルは必須です.', field: :title) if title.blank?
return render_unprocessable_entity('本文は必須です.', field: :body) if body.blank?
tag_name = TagName.find_undiscard_or_create_by!(name: title)
tag_name = TagName.find_or_create_by!(name: title)
page =
Wiki::Commit.create_content!(
+3
ファイルの表示
@@ -63,16 +63,19 @@ class Post < ApplicationRecord
has_many :user_post_views, dependent: :delete_all
has_many :post_similarities, dependent: :delete_all
has_many :post_versions
has_many :gekanator_guessed_games,
class_name: 'GekanatorGame',
foreign_key: :guessed_post_id,
dependent: :delete_all,
inverse_of: :guessed_post
has_many :gekanator_correct_games,
class_name: 'GekanatorGame',
foreign_key: :correct_post_id,
dependent: :delete_all,
inverse_of: :correct_post
has_many :gekanator_question_examples, dependent: :delete_all
has_many :parent_post_implications,
+5 -7
ファイルの表示
@@ -2,8 +2,6 @@ require 'set'
class Tag < ApplicationRecord
include MyDiscard
class NicoTagNormalisationError < ArgumentError
;
end
@@ -232,10 +230,10 @@ class Tag < ApplicationRecord
end
def self.find_or_create_by_tag_name! name, category:
tn = TagName.find_undiscard_or_create_by!(name: name.to_s.strip)
tn = TagName.find_or_create_by!(name: name.to_s.strip)
tn = tn.canonical if tn.canonical_id?
Tag.find_undiscard_or_create_by!(tag_name_id: tn.id) do |t|
Tag.find_or_create_by!(tag_name_id: tn.id) do |t|
t.category = category
end
rescue ActiveRecord::RecordNotUnique
@@ -273,10 +271,10 @@ class Tag < ApplicationRecord
end
TagVersioning.record!(source_tag, event_type: :discard, created_by_user:)
source_tag.discard!
source_tag.destroy!
if source_tag.nico?
source_tag_name.discard!
source_tag_name.destroy!
else
source_tag_name.update_columns(canonical_id: target_tag.tag_name_id,
updated_at: Time.current)
@@ -297,7 +295,7 @@ class Tag < ApplicationRecord
target_tag.reload
end
def snapshot_aliases = tag_name.aliases.kept.order(:name).pluck(:name)
def snapshot_aliases = tag_name.aliases.order(:name).pluck(:name)
def snapshot_parent_tag_ids = parents.order(:id).pluck(:id)
-2
ファイルの表示
@@ -1,6 +1,4 @@
class TagName < ApplicationRecord
include MyDiscard
has_one :tag
has_one :wiki_page
+1 -1
ファイルの表示
@@ -32,7 +32,7 @@ class TagNameSanitisationRule < ApplicationRecord
elsif source_tag
source_tag.update_columns(tag_name_id: existing_tn.id, updated_at: Time.current)
end
tn.discard!
tn.destroy!
next
end