タグの合併処理追加(#282) #284

マージ済み
みてるぞ が 6 個のコミットを feature/282 から main へマージ 2026-03-08 15:46:06 +09:00
コミット 613b668843 の変更だけを表示してゐます - すべてのコミットを表示
+9 -10
ファイルの表示
@@ -48,7 +48,7 @@ class Tag < ApplicationRecord
validate :tag_name_must_be_canonical
validate :category_must_be_deerjikist_with_deerjikists
scope :nico_tags, -> { where(category: :nico) }
scope :nico_tags, -> { nico }
CATEGORY_PREFIXES = {
'general:' => :general,
@@ -97,14 +97,12 @@ class Tag < ApplicationRecord
pf, cat = CATEGORY_PREFIXES.find { |p, _| name.downcase.start_with?(p) } || ['', nil]
name = TagName.canonicalise(name.sub(/\A#{ pf }/i, '')).first
find_or_create_by_tag_name!(name, category: (cat || :general)).tap do |tag|
if cat && tag.category != cat
tag.update!(category: cat)
end
tag.update!(category: cat) if cat && tag.category != cat
end
end
tags << Tag.tagme if with_tagme && tags.size < 10 && tags.none?(Tag.tagme)
tags << Tag.no_deerjikist if tags.all? { |t| t.category != 'deerjikist' }
tags << Tag.no_deerjikist if tags.all? { |t| !(t.deerjikist?) }
tags.uniq(&:id)
end
@@ -166,19 +164,20 @@ class Tag < ApplicationRecord
tag_name.reload
tag_name.update!(canonical: target_tag.tag_name)
end
# 再集計
target_tag.update_columns(post_count: PostTag.kept.where(tag: target_tag).count)
end
target_tag.update!(post_count: PostTag.kept.where(tag: target_tag).count)
target_tag
target_tag.reload
end
private
def nico_tag_name_must_start_with_nico
n = name.to_s
if ((category == 'nico' && !(n.downcase.start_with?('nico:'))) ||
(category != 'nico' && n.downcase.start_with?('nico:')))
if ((nico? && !(n.downcase.start_with?('nico:'))) ||
(!(nico?) && n.downcase.start_with?('nico:')))
errors.add :name, 'ニコニコ・タグの命名規則に反してゐます.'
end
end